forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-http2-server-too-large-headers.js
51 lines (46 loc) · 1.61 KB
/
test-http2-server-too-large-headers.js
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
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');
const assert = require('assert');
const {
DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE,
// NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE
} = http2.constants;
for (const headerSize of [
DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE - 101, // pass
DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE - 100, // fail
]) {
const timeout = common.platformTimeout(50);
const timer = setTimeout(() => assert.fail(`http2 client timedout when receiving a header of size ${headerSize}`), timeout);
const server = http2.createServer((req, res) => {
res.setHeader('foobar', 'a'.repeat(headerSize));
res.end(common.mustCall());
});
server.on('error', common.mustNotCall());
server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
client.on('remoteSettings', () => {
const req = client.request({ ':path': '/' });
// TODO, I don't yet know which error to expect
// req.on('error',
// (error) => common.expectsError({
// code: 'ERR_HTTP2_STREAM_ERROR',
// name: 'Error',
// message:
// 'Stream closed with error code NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE'
// }));
req.on('close', common.mustCall(() => {
clearTimeout(timer);
// TODO, I don't yet know which error code to expect
// assert.strictEqual(
// req.rstCode,
// NGHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE
// );
server.close();
client.close();
}));
});
}));
}