Skip to content

Commit

Permalink
http2: do not modify explicity set date headers
Browse files Browse the repository at this point in the history
Fixes: #30894
Refs: #29829

PR-URL: #33160
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
rexagod authored and codebytere committed Jun 18, 2020
1 parent 2380d90 commit 7ccb021
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
10 changes: 10 additions & 0 deletions doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,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 @@ -1453,6 +1457,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 @@ -1551,6 +1558,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 @@ -2222,7 +2222,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();
});
}));

0 comments on commit 7ccb021

Please sign in to comment.