Skip to content

Commit 4df82be

Browse files
committed
Handle review comments on respond header prep & sentHeader testing
1 parent 16133f2 commit 4df82be

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

lib/internal/http2/core.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,7 +2565,7 @@ function prepareResponseHeaders(stream, headersParam, options) {
25652565
}
25662566

25672567
function prepareResponseHeadersObject(oldHeaders, options) {
2568-
assertIsObject(oldHeaders, 'headers');
2568+
assertIsObject(oldHeaders, 'headers', ['Object', 'Array']);
25692569
const headers = { __proto__: null };
25702570

25712571
if (oldHeaders !== null && oldHeaders !== undefined) {
@@ -2586,18 +2586,7 @@ function prepareResponseHeadersObject(oldHeaders, options) {
25862586
headers[HTTP2_HEADER_DATE] ??= utcDate();
25872587
}
25882588

2589-
// This is intentionally stricter than the HTTP/1 implementation, which
2590-
// allows values between 100 and 999 (inclusive) in order to allow for
2591-
// backwards compatibility with non-spec compliant code. With HTTP/2,
2592-
// we have the opportunity to start fresh with stricter spec compliance.
2593-
// This will have an impact on the compatibility layer for anyone using
2594-
// non-standard, non-compliant status codes.
2595-
if (statusCode < 200 || statusCode > 599)
2596-
throw new ERR_HTTP2_STATUS_INVALID(headers[HTTP2_HEADER_STATUS]);
2597-
2598-
const neverIndex = headers[kSensitiveHeaders];
2599-
if (neverIndex !== undefined && !ArrayIsArray(neverIndex))
2600-
throw new ERR_INVALID_ARG_VALUE('headers[http2.neverIndex]', neverIndex);
2589+
validatePreparedResponseHeaders(headers, statusCode);
26012590

26022591
return {
26032592
headers,
@@ -2629,6 +2618,12 @@ function prepareResponseHeadersArray(headers, options) {
26292618
headers.push(HTTP2_HEADER_DATE, utcDate());
26302619
}
26312620

2621+
validatePreparedResponseHeaders(headers, statusCode);
2622+
2623+
return { headers, statusCode };
2624+
}
2625+
2626+
function validatePreparedResponseHeaders(headers, statusCode) {
26322627
// This is intentionally stricter than the HTTP/1 implementation, which
26332628
// allows values between 100 and 999 (inclusive) in order to allow for
26342629
// backwards compatibility with non-spec compliant code. With HTTP/2,
@@ -2641,8 +2636,6 @@ function prepareResponseHeadersArray(headers, options) {
26412636
const neverIndex = headers[kSensitiveHeaders];
26422637
if (neverIndex !== undefined && !ArrayIsArray(neverIndex))
26432638
throw new ERR_INVALID_ARG_VALUE('headers[http2.neverIndex]', neverIndex);
2644-
2645-
return { headers, statusCode };
26462639
}
26472640

26482641
function onFileUnpipe() {

test/parallel/test-http2-raw-headers-defaults.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ const http2 = require('http2');
2323
'x-FOO', 'bar',
2424
'x', '2',
2525
]);
26+
27+
assert.partialDeepStrictEqual(stream.sentHeaders, {
28+
'__proto__': null,
29+
':status': 200,
30+
'x': [ '1', '2' ],
31+
'x-FOO': 'bar',
32+
});
33+
34+
assert.strictEqual(typeof stream.sentHeaders.date, 'string');
35+
2636
stream.end();
2737
}));
2838

0 commit comments

Comments
 (0)