Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2: allow explicity setting date headers #33160

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,10 @@ and will throw an error.
#### `http2stream.respond([headers[, options]])`
<!-- YAML
added: v8.4.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/33160
description: Allow explicity setting date headers.
-->

* `headers` {HTTP/2 Headers Object}
Expand Down Expand Up @@ -1450,6 +1454,9 @@ server.on('stream', (stream) => {
<!-- YAML
added: v8.4.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/33160
description: Allow explicity setting date headers.
- version: v12.12.0
pr-url: https://github.com/nodejs/node/pull/29876
description: The `fd` option may now be a `FileHandle`.
Expand Down Expand Up @@ -1548,6 +1555,9 @@ server.on('stream', (stream) => {
<!-- YAML
added: v8.4.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/33160
description: Allow explicity setting date headers.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18936
description: Any readable file, not necessarily a
Expand Down
5 changes: 4 additions & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2234,7 +2234,10 @@ function processHeaders(oldHeaders) {
const statusCode =
headers[HTTP2_HEADER_STATUS] =
headers[HTTP2_HEADER_STATUS] | 0 || HTTP_STATUS_OK;
headers[HTTP2_HEADER_DATE] = utcDate();

if (headers[HTTP2_HEADER_DATE] === null ||
headers[HTTP2_HEADER_DATE] === undefined)
headers[HTTP2_HEADER_DATE] = utcDate();

// This is intentionally stricter than the HTTP/1 implementation, which
// allows values between 100 and 999 (inclusive) in order to allow for
Expand Down
22 changes: 22 additions & 0 deletions test/parallel/test-http2-removed-header-stays-removed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'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(common.mustCall((request, response) => {
response.setHeader('date', 'snacks o clock');
response.end();
}));

server.listen(0, common.mustCall(() => {
const session = http2.connect(`http://localhost:${server.address().port}`);
const req = session.request();
req.on('response', (headers, flags) => {
assert.deepStrictEqual(headers.date, 'snacks o clock');
});
req.on('end', () => {
session.close();
server.close();
});
}));