-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-http2-compat-write-early-hints-invalid-header.js
More file actions
60 lines (45 loc) · 1.54 KB
/
test-http2-compat-write-early-hints-invalid-header.js
File metadata and controls
60 lines (45 loc) · 1.54 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
const common = require('../common');
if (!common.hasCrypto) common.skip('missing crypto');
const assert = require('node:assert');
const http2 = require('node:http2');
const debug = require('node:util').debuglog('test');
const testResBody = 'response content';
{
const server = http2.createServer();
server.on('request', common.mustCall((req, res) => {
debug('Server sending early hints...');
assert.throws(() => {
res.writeEarlyHints({
'link': '</styles.css>; rel=preload; as=style',
'x\rbad': 'value',
});
}, (err) => err.code === 'ERR_INVALID_HTTP_TOKEN');
assert.throws(() => {
res.writeEarlyHints({
'link': '</styles.css>; rel=preload; as=style',
'x-custom': undefined,
});
}, (err) => err.code === 'ERR_HTTP2_INVALID_HEADER_VALUE');
debug('Server sending full response...');
res.end(testResBody);
}));
server.listen(0);
server.on('listening', common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
debug('Client sending request...');
req.on('headers', common.mustNotCall());
req.on('response', common.mustCall((headers) => {
assert.strictEqual(headers[':status'], 200);
}));
let data = '';
req.on('data', common.mustCallAtLeast((d) => data += d));
req.on('end', common.mustCall(() => {
debug('Got full response.');
assert.strictEqual(data, testResBody);
client.close();
server.close();
}));
}));
}