Skip to content

Commit

Permalink
http2: do not modify explicity set date headers
Browse files Browse the repository at this point in the history
  • Loading branch information
rexagod committed Apr 30, 2020
1 parent 307c67b commit 0825806
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
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.

'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) {
response.setHeader('date', 'snacks o clock');
response.end();
}));

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

0 comments on commit 0825806

Please sign in to comment.