/
test-http2-invalidheaderfields-client.js
61 lines (55 loc) · 1.56 KB
/
test-http2-invalidheaderfields-client.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
52
53
54
55
56
57
58
59
60
61
'use strict';
const common = require('../common');
if (!common.hasCrypto) { common.skip('missing crypto'); }
const assert = require('assert');
const http2 = require('http2');
const server1 = http2.createServer();
server1.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server1.address().port}`);
// Check for req headers
assert.throws(() => {
session.request({ 'no underscore': 123 });
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
});
session.on('error', common.mustCall((e) => {
assert.strictEqual(e.code, 'ERR_INVALID_HTTP_TOKEN');
server1.close();
}));
}));
const server2 = http2.createServer(common.mustCall((req, res) => {
// check for setHeader
assert.throws(() => {
res.setHeader('x y z', 123);
}, {
code: 'ERR_INVALID_HTTP_TOKEN'
});
res.end();
}));
server2.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server2.address().port}`);
const req = session.request();
req.on('end', common.mustCall(() => {
session.close();
server2.close();
}));
}));
const server3 = http2.createServer(common.mustCall((req, res) => {
// check for writeHead
assert.throws(common.mustCall(() => {
res.writeHead(200, {
'an invalid header': 123
});
}), {
code: 'ERR_INVALID_HTTP_TOKEN'
});
res.end();
}));
server3.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server3.address().port}`);
const req = session.request();
req.on('end', common.mustCall(() => {
server3.close();
session.close();
}));
}));