From 5043a6e0600f6b7f100c182991b7cb32850b2749 Mon Sep 17 00:00:00 2001 From: Genki Takiuchi Date: Sat, 1 Jul 2023 17:40:01 +0900 Subject: [PATCH 1/3] Ignore status message for HTTP/2 --- index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f628e42..dfe6c6b 100644 --- a/index.js +++ b/index.js @@ -276,7 +276,9 @@ function send (req, res, status, headers, message) { // response status res.statusCode = status - res.statusMessage = statuses.message[status] + if (req.httpVersionMajor < 2) { + res.statusMessage = statuses.message[status] + } // remove any content headers res.removeHeader('Content-Encoding') From 9dac157142b061dfa4ce8e551833d8065e6580da Mon Sep 17 00:00:00 2001 From: Genki Takiuchi Date: Sun, 2 Jul 2023 02:19:56 +0900 Subject: [PATCH 2/3] Added a test to check no warnings on HTTP/2 --- test/test.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/test.js b/test/test.js index a815654..3e2ab0a 100644 --- a/test/test.js +++ b/test/test.js @@ -577,4 +577,43 @@ describe('finalhandler(req, res)', function () { }) }) }) + + describe('HTTP/2', function () { + it('should respond 404 without warning', function (done) { + var warned = false + process.on('warning', function (warning) { + warned = true + }) + + var http2 + try { + http2 = require('http2') + } catch (e) { + return done() + } + + var server = http2.createServer(function (req, res) { + var done = finalhandler(req, res) + done() + }) + + server.listen(0, function () { + var port = server.address().port + var client = http2.connect('http://localhost:' + port) + var req = client.request({ + ':method': 'GET', + ':path': '/foo' + }) + + req.on('response', function (headers) { + assert.strictEqual(headers[':status'], 404) + req.close() + client.close() + server.close() + assert.strictEqual(warned, false) + done() + }) + }) + }) + }) }) From cffa0da81d23f96846f550f11fbff6c26ba4900a Mon Sep 17 00:00:00 2001 From: Genki Takiuchi Date: Sun, 2 Jul 2023 02:38:58 +0900 Subject: [PATCH 3/3] Check the name and message of the warning. --- test/test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test.js b/test/test.js index 3e2ab0a..46bedfb 100644 --- a/test/test.js +++ b/test/test.js @@ -582,6 +582,8 @@ describe('finalhandler(req, res)', function () { it('should respond 404 without warning', function (done) { var warned = false process.on('warning', function (warning) { + if (warning.name !== 'UnsupportedWarning') return + if (!warning.message.match(/Status message is not supported/)) return warned = true })