Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Expand HTTP/2 raw tests to cover request & respond defaults
  • Loading branch information
pimterry committed Aug 13, 2025
commit b347c7c47ee129762546fb285a5405246c3e33c6
66 changes: 66 additions & 0 deletions test/parallel/test-http2-raw-headers-defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'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',
]);
stream.end();
Comment thread
pimterry marked this conversation as resolved.
}));


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();
}));
}));
}
26 changes: 18 additions & 8 deletions test/parallel/test-http2-raw-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,29 @@ const http2 = require('http2');
assert.deepStrictEqual(rawHeaders, [
':path', '/foobar',
':scheme', 'http',
':authority', `localhost:${server.address().port}`,
':method', 'GET',
':authority', `test.invalid:${server.address().port}`,
':method', 'POST',
'a', 'b',
'x-foo', 'bar', // Lowercased as required for HTTP/2
'a', 'c', // Duplicate header order preserved
]);

stream.respond([
':status', '200',
':status', '404',
'x', '1',
'x-FOO', 'bar',
'x', '2',
'DATE', '0000',
]);

assert.deepStrictEqual(stream.sentHeaders, {
'__proto__': null,
':status': '404',
'x': [ '1', '2' ],
'x-FOO': 'bar',
'DATE': '0000',
});

stream.end();
}));

Expand All @@ -36,8 +46,8 @@ const http2 = require('http2');
const req = client.request([
':path', '/foobar',
':scheme', 'http',
':authority', `localhost:${server.address().port}`,
':method', 'GET',
':authority', `test.invalid:${server.address().port}`,
':method', 'POST',
'a', 'b',
'x-FOO', 'bar',
'a', 'c',
Expand All @@ -47,15 +57,15 @@ const http2 = require('http2');
'__proto__': null,
':path': '/foobar',
':scheme': 'http',
':authority': `localhost:${server.address().port}`,
':method': 'GET',
':authority': `test.invalid:${server.address().port}`,
':method': 'POST',
'a': [ 'b', 'c' ],
'x-FOO': 'bar',
});

req.on('response', common.mustCall((_headers, _flags, rawHeaders) => {
assert.deepStrictEqual(rawHeaders, [
':status', '200',
':status', '404',
'x', '1',
'x-foo', 'bar', // Lowercased as required for HTTP/2
'x', '2', // Duplicate header order preserved
Expand Down
Loading