Skip to content

Commit cfbf505

Browse files
apapirovskiMylesBorins
authored andcommitted
test: add http2 test for method CONNECT
Adds test case for default handling of method CONNECT, as well as the ability to bind a connect listener and handle the request. PR-URL: #15052 Refs: #14985 Reviewed-By: James M Snell <[email protected]>
1 parent 9129057 commit cfbf505

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Flags: --expose-http2
2+
'use strict';
3+
4+
const common = require('../common');
5+
if (!common.hasCrypto)
6+
common.skip('missing crypto');
7+
const assert = require('assert');
8+
const http2 = require('http2');
9+
10+
const server = http2.createServer(common.mustNotCall());
11+
12+
server.listen(0, common.mustCall(() => testMethodConnect(2)));
13+
14+
server.once('connect', common.mustCall((req, res) => {
15+
assert.strictEqual(req.headers[':method'], 'CONNECT');
16+
res.statusCode = 405;
17+
res.end();
18+
}));
19+
20+
function testMethodConnect(testsToRun) {
21+
if (!testsToRun) {
22+
return server.close();
23+
}
24+
25+
const port = server.address().port;
26+
const client = http2.connect(`http://localhost:${port}`);
27+
const req = client.request({
28+
':method': 'CONNECT',
29+
':authority': `localhost:${port}`
30+
});
31+
32+
req.on('response', common.mustCall((headers) => {
33+
assert.strictEqual(headers[':status'], 405);
34+
}));
35+
req.resume();
36+
req.on('end', common.mustCall(() => {
37+
client.destroy();
38+
testMethodConnect(testsToRun - 1);
39+
}));
40+
req.end();
41+
}

0 commit comments

Comments
 (0)