Skip to content

Commit 7ccb021

Browse files
rexagodcodebytere
authored andcommitted
http2: do not modify explicity set date headers
Fixes: #30894 Refs: #29829 PR-URL: #33160 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 2380d90 commit 7ccb021

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

doc/api/http2.md

+10
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,10 @@ and will throw an error.
14091409
#### `http2stream.respond([headers[, options]])`
14101410
<!-- YAML
14111411
added: v8.4.0
1412+
changes:
1413+
- version: REPLACEME
1414+
pr-url: https://github.com/nodejs/node/pull/33160
1415+
description: Allow explicity setting date headers.
14121416
-->
14131417

14141418
* `headers` {HTTP/2 Headers Object}
@@ -1453,6 +1457,9 @@ server.on('stream', (stream) => {
14531457
<!-- YAML
14541458
added: v8.4.0
14551459
changes:
1460+
- version: REPLACEME
1461+
pr-url: https://github.com/nodejs/node/pull/33160
1462+
description: Allow explicity setting date headers.
14561463
- version: v12.12.0
14571464
pr-url: https://github.com/nodejs/node/pull/29876
14581465
description: The `fd` option may now be a `FileHandle`.
@@ -1551,6 +1558,9 @@ server.on('stream', (stream) => {
15511558
<!-- YAML
15521559
added: v8.4.0
15531560
changes:
1561+
- version: REPLACEME
1562+
pr-url: https://github.com/nodejs/node/pull/33160
1563+
description: Allow explicity setting date headers.
15541564
- version: v10.0.0
15551565
pr-url: https://github.com/nodejs/node/pull/18936
15561566
description: Any readable file, not necessarily a

lib/internal/http2/core.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2222,7 +2222,10 @@ function processHeaders(oldHeaders) {
22222222
const statusCode =
22232223
headers[HTTP2_HEADER_STATUS] =
22242224
headers[HTTP2_HEADER_STATUS] | 0 || HTTP_STATUS_OK;
2225-
headers[HTTP2_HEADER_DATE] = utcDate();
2225+
2226+
if (headers[HTTP2_HEADER_DATE] === null ||
2227+
headers[HTTP2_HEADER_DATE] === undefined)
2228+
headers[HTTP2_HEADER_DATE] = utcDate();
22262229

22272230
// This is intentionally stricter than the HTTP/1 implementation, which
22282231
// allows values between 100 and 999 (inclusive) in order to allow for
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (!common.hasCrypto) { common.skip('missing crypto'); }
4+
const assert = require('assert');
5+
const http2 = require('http2');
6+
7+
const server = http2.createServer(common.mustCall((request, response) => {
8+
response.setHeader('date', 'snacks o clock');
9+
response.end();
10+
}));
11+
12+
server.listen(0, common.mustCall(() => {
13+
const session = http2.connect(`http://localhost:${server.address().port}`);
14+
const req = session.request();
15+
req.on('response', (headers, flags) => {
16+
assert.deepStrictEqual(headers.date, 'snacks o clock');
17+
});
18+
req.on('end', () => {
19+
session.close();
20+
server.close();
21+
});
22+
}));

0 commit comments

Comments
 (0)