From 014c725d8a9738f966dfa41e7b4ece3edc82a2e4 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 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 --- doc/api/http2.md | 31 ++++++++- 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, 131 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 00aacd4335a200..739d1eab5ba22a 100644 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -2,6 +2,10 @@