Skip to content

Commit d176a18

Browse files
apapirovskiMylesBorins
authored andcommitted
test: add a test for Expect & checkExpectation
New test case for Expect header & checkExpectation event based on the existing http test case. PR-URL: #15040 Refs: #14985 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent cfbf505 commit d176a18

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 expectValue = 'meoww';
11+
12+
const server = http2.createServer(common.mustNotCall());
13+
14+
server.once('checkExpectation', common.mustCall((req, res) => {
15+
assert.strictEqual(req.headers['expect'], expectValue);
16+
res.statusCode = 417;
17+
res.end();
18+
}));
19+
20+
server.listen(0, common.mustCall(() => nextTest(2)));
21+
22+
function nextTest(testsToRun) {
23+
if (!testsToRun) {
24+
return server.close();
25+
}
26+
27+
const port = server.address().port;
28+
const client = http2.connect(`http://localhost:${port}`);
29+
const req = client.request({
30+
':path': '/',
31+
':method': 'GET',
32+
':scheme': 'http',
33+
':authority': `localhost:${port}`,
34+
expect: expectValue
35+
});
36+
37+
req.on('response', common.mustCall((headers) => {
38+
assert.strictEqual(headers[':status'], 417);
39+
req.resume();
40+
}));
41+
42+
req.on('end', common.mustCall(() => {
43+
client.destroy();
44+
nextTest(testsToRun - 1);
45+
}));
46+
}

0 commit comments

Comments
 (0)