Skip to content
This repository was archived by the owner on Jul 6, 2018. It is now read-only.

Commit 8f99d44

Browse files
http2: add test for invalid pseudo headers
1 parent 1ef9111 commit 8f99d44

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Flags: --expose-http2
2+
'use strict';
3+
4+
const common = require('../common');
5+
const assert = require('assert');
6+
const http2 = require('http2');
7+
const body =
8+
'Cannot set HTTP/2 pseudo-headers';
9+
10+
const invalidHeaders = [
11+
{ key: ':status', value: 200 },
12+
{ key: ':method', value: 'GET' },
13+
{ key: ':path', value: '/' },
14+
{ key: ':authority', value: 'example.com' },
15+
{ key: ':scheme', value: 'http' }
16+
];
17+
18+
const checkServer = (header, value) => {
19+
const server = http2.createServer((req, res) => {
20+
try {
21+
res.setHeader('foobar', 'baz');
22+
res.setHeader('X-POWERED-BY', 'node-test');
23+
// invalid header
24+
res.setHeader(header, value);
25+
} catch (e) {
26+
res.statusCode = 500;
27+
res.end(e.message);
28+
}
29+
});
30+
31+
server.listen(0, common.mustCall(() => {
32+
const client = http2.connect(`http://localhost:${server.address().port}`);
33+
const headers = { ':path': '/' };
34+
const req = client.request(headers);
35+
req.on('response', common.mustCall((headers) => {
36+
assert.strictEqual(headers[':status'], 500);
37+
assert.strictEqual(headers['foobar'], 'baz');
38+
assert.strictEqual(headers['x-powered-by'], 'node-test');
39+
}));
40+
41+
let data = '';
42+
req.on('data', (d) => data += d);
43+
req.on('end', common.mustCall(() => {
44+
assert.strictEqual(body, data);
45+
server.close();
46+
client.destroy();
47+
}));
48+
req.end();
49+
}));
50+
server.on('error', common.mustNotCall());
51+
};
52+
53+
invalidHeaders.forEach(({ key, value }) => {
54+
checkServer(key, value);
55+
});

0 commit comments

Comments
 (0)