From 0825806c35edbe14a283faea5bef59c8fe42bb45 Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Sun, 26 Apr 2020 03:29:17 +0530 Subject: [PATCH 1/3] http2: do not modify explicity set date headers Fixes: https://github.com/nodejs/node/issues/30894 Refs: https://github.com/nodejs/node/issues/29829 --- lib/internal/http2/core.js | 5 ++- ...test-http2-removed-header-stays-removed.js | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-http2-removed-header-stays-removed.js diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index ef5d61843448c6..e06491e325309e 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -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 diff --git a/test/parallel/test-http2-removed-header-stays-removed.js b/test/parallel/test-http2-removed-header-stays-removed.js new file mode 100644 index 00000000000000..a05a3d6386c71a --- /dev/null +++ b/test/parallel/test-http2-removed-header-stays-removed.js @@ -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(); + }); +})); From 7cb1a7d00e8a0b61030d5f28497aba4f5ce3ec7b Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Sat, 2 May 2020 13:17:09 +0530 Subject: [PATCH 2/3] fixup: add YAML logs --- doc/api/http2.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/api/http2.md b/doc/api/http2.md index ceda983559d1ed..89d21cc185cf38 100644 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -1406,6 +1406,10 @@ and will throw an error. #### `http2stream.respond([headers[, options]])` * `headers` {HTTP/2 Headers Object} @@ -1450,6 +1454,9 @@ server.on('stream', (stream) => {