From f5c0e282ccf98e17f295c11850649ad19a6fff51 Mon Sep 17 00:00:00 2001 From: Alba Mendez Date: Fri, 7 Aug 2020 12:54:08 +0200 Subject: [PATCH] http2: allow Host in HTTP/2 requests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The HTTP/2 spec allows Host to be used instead of :authority in requests, and this is in fact *preferred* when converting from HTTP/1. We erroneously treated Host as a connection header, thus disallowing it in requests. The patch corrects this, aligning Node.js behaviour with the HTTP/2 spec and with nghttp2: - Treat Host as a single-value header instead of a connection header. - Don't autofill :authority if Host is present. - The compatibility API (request.authority) falls back to using Host if :authority is not present. This is semver-major because requests are no longer guaranteed to have :authority set. An explanatory note was added to the docs. Fixes: https://github.com/nodejs/node/issues/29858 PR-URL: https://github.com/nodejs/node/pull/34664 Reviewed-By: James M Snell Reviewed-By: Gerhard Stöbich Reviewed-By: Yongsheng Zhang Reviewed-By: Matteo Collina Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: Ricky Zhou <0x19951125@gmail.com> --- doc/api/http2.md | 25 +++++++- lib/internal/http2/compat.js | 5 +- lib/internal/http2/core.js | 9 +-- lib/internal/http2/util.js | 16 ++++- .../test-http2-compat-serverrequest-host.js | 63 +++++++++++++++++++ test/parallel/test-http2-util-headers-list.js | 21 ++++++- 6 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 test/parallel/test-http2-compat-serverrequest-host.js diff --git a/doc/api/http2.md b/doc/api/http2.md index c8c51ed92ef247..5adf84e27f8b53 100644 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -2,6 +2,10 @@