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 2 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
43 changes: 43 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,43 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
rexagod marked this conversation as resolved.
Show resolved Hide resolved

rexagod marked this conversation as resolved.
Show resolved Hide resolved
'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(function(request, response) {
rexagod marked this conversation as resolved.
Show resolved Hide resolved
response.setHeader('date', 'snacks o clock');
response.end();
}));

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