forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-h2-large-header-cause-client-to-hangup.js
More file actions
44 lines (37 loc) · 1.32 KB
/
test-h2-large-header-cause-client-to-hangup.js
File metadata and controls
44 lines (37 loc) · 1.32 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
'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_FRAME_SIZE_ERROR,
} = http2.constants;
const headerSize = DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE;
const timeout = common.platformTimeout(2_000);
const timer = setTimeout(() => assert.fail(`http2 client timedout
when server can not manage to send a header of size ${headerSize}`), timeout);
const server = http2.createServer((req, res) => {
res.setHeader('foobar', 'a'.repeat(DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE));
res.end();
});
server.listen(0, common.mustCall(() => {
const clientSession = http2.connect(`http://localhost:${server.address().port}`);
clientSession.on('close', common.mustCall());
clientSession.on('remoteSettings', send);
function send() {
const stream = clientSession.request({ ':path': '/' });
stream.on('close', common.mustCall(() => {
assert.strictEqual(stream.rstCode, NGHTTP2_FRAME_SIZE_ERROR);
clearTimeout(timer);
server.close();
}));
stream.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
name: 'Error',
message: 'Stream closed with error code NGHTTP2_FRAME_SIZE_ERROR'
}));
stream.end();
}
}));