Skip to content

Commit 4d0129a

Browse files
rexagodaddaleax
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 867c451 commit 4d0129a

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

doc/api/http2.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,10 @@ and will throw an error.
14291429
#### `http2stream.respond([headers[, options]])`
14301430
<!-- YAML
14311431
added: v8.4.0
1432+
changes:
1433+
- version: REPLACEME
1434+
pr-url: https://github.com/nodejs/node/pull/33160
1435+
description: Allow explicity setting date headers.
14321436
-->
14331437

14341438
* `headers` {HTTP/2 Headers Object}
@@ -1473,6 +1477,9 @@ server.on('stream', (stream) => {
14731477
<!-- YAML
14741478
added: v8.4.0
14751479
changes:
1480+
- version: REPLACEME
1481+
pr-url: https://github.com/nodejs/node/pull/33160
1482+
description: Allow explicity setting date headers.
14761483
- version: v12.12.0
14771484
pr-url: https://github.com/nodejs/node/pull/29876
14781485
description: The `fd` option may now be a `FileHandle`.
@@ -1571,6 +1578,9 @@ server.on('stream', (stream) => {
15711578
<!-- YAML
15721579
added: v8.4.0
15731580
changes:
1581+
- version: REPLACEME
1582+
pr-url: https://github.com/nodejs/node/pull/33160
1583+
description: Allow explicity setting date headers.
15741584
- version: v10.0.0
15751585
pr-url: https://github.com/nodejs/node/pull/18936
15761586
description: Any readable file, not necessarily a

lib/internal/http2/core.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2199,7 +2199,10 @@ function processHeaders(oldHeaders) {
21992199
const statusCode =
22002200
headers[HTTP2_HEADER_STATUS] =
22012201
headers[HTTP2_HEADER_STATUS] | 0 || HTTP_STATUS_OK;
2202-
headers[HTTP2_HEADER_DATE] = utcDate();
2202+
2203+
if (headers[HTTP2_HEADER_DATE] === null ||
2204+
headers[HTTP2_HEADER_DATE] === undefined)
2205+
headers[HTTP2_HEADER_DATE] = utcDate();
22032206

22042207
// This is intentionally stricter than the HTTP/1 implementation, which
22052208
// allows values between 100 and 999 (inclusive) in order to allow for
Lines changed: 22 additions & 0 deletions
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)