forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-http2-issue-32922.js
More file actions
73 lines (67 loc) · 1.96 KB
/
Copy pathtest-http2-issue-32922.js
File metadata and controls
73 lines (67 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');
const net = require('net');
const {
HTTP2_HEADER_PATH,
} = http2.constants;
// Create a normal session, as a control case
function normalSession(cb) {
http2.connect('https://google.com', (clientSession) => {
let error = null;
const req = clientSession.request({ [HTTP2_HEADER_PATH]: '/' });
req.on('error', (err) => {
error = err;
});
req.on('response', (_headers) => {
req.on('data', (_chunk) => { });
req.on('end', () => {
clientSession.close();
return cb(error);
});
});
});
}
normalSession(common.mustSucceed());
// Create a session using a socket that has not yet finished connecting
function socketNotFinished(done) {
const socket2 = net.connect(443, 'google.com');
http2.connect('https://google.com', { socket2 }, (clientSession) => {
let error = null;
const req = clientSession.request({ [HTTP2_HEADER_PATH]: '/' });
req.on('error', (err) => {
error = err;
});
req.on('response', (_headers) => {
req.on('data', (_chunk) => { });
req.on('end', () => {
clientSession.close();
socket2.destroy();
return done(error);
});
});
});
}
socketNotFinished(common.mustSucceed());
// Create a session using a socket that has finished connecting
function socketFinished(done) {
const socket = net.connect(443, 'google.com', () => {
http2.connect('https://google.com', { socket }, (clientSession) => {
let error = null;
const req = clientSession.request({ [HTTP2_HEADER_PATH]: '/' });
req.on('error', (err) => {
error = err;
});
req.on('response', (_headers) => {
req.on('data', (_chunk) => { });
req.on('end', () => {
clientSession.close();
return done(error);
});
});
});
});
}
socketFinished(common.mustSucceed());