forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-http2-raw-headers-defaults.js
More file actions
76 lines (64 loc) · 1.91 KB
/
test-http2-raw-headers-defaults.js
File metadata and controls
76 lines (64 loc) · 1.91 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const http2 = require('http2');
{
const server = http2.createServer();
server.on('stream', common.mustCall((stream, _headers, _flags, rawHeaders) => {
assert.deepStrictEqual(rawHeaders, [
':method', 'GET',
':authority', `localhost:${server.address().port}`,
':scheme', 'http',
':path', '/',
'a', 'b',
'x-foo', 'bar', // Lowercased as required for HTTP/2
'a', 'c', // Duplicate header order preserved
]);
stream.respond([
'x', '1',
'x-FOO', 'bar',
'x', '2',
]);
assert.partialDeepStrictEqual(stream.sentHeaders, {
'__proto__': null,
':status': 200,
'x': [ '1', '2' ],
'x-FOO': 'bar',
});
assert.strictEqual(typeof stream.sentHeaders.date, 'string');
stream.end();
}));
server.listen(0, common.mustCall(() => {
const port = server.address().port;
const client = http2.connect(`http://localhost:${port}`);
const req = client.request([
'a', 'b',
'x-FOO', 'bar',
'a', 'c',
]).end();
assert.deepStrictEqual(req.sentHeaders, {
'__proto__': null,
':path': '/',
':scheme': 'http',
':authority': `localhost:${server.address().port}`,
':method': 'GET',
'a': [ 'b', 'c' ],
'x-FOO': 'bar',
});
req.on('response', common.mustCall((_headers, _flags, rawHeaders) => {
assert.strictEqual(rawHeaders.length, 10);
assert.deepStrictEqual(rawHeaders.slice(0, 8), [
':status', '200',
'x', '1',
'x-foo', 'bar', // Lowercased as required for HTTP/2
'x', '2', // Duplicate header order preserved
]);
assert.strictEqual(rawHeaders[8], 'date');
assert.strictEqual(typeof rawHeaders[9], 'string');
client.close();
server.close();
}));
}));
}