From a867325a6fd751aea8f920d3b1ea299a0742a801 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 27 Jan 2022 12:03:49 -0500 Subject: [PATCH 1/3] strip out HTTP/2 headers in getRequest --- packages/kit/src/node.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/kit/src/node.js b/packages/kit/src/node.js index 44d3ae388873..5e70731c78f1 100644 --- a/packages/kit/src/node.js +++ b/packages/kit/src/node.js @@ -52,9 +52,19 @@ function get_raw_body(req) { /** @type {import('@sveltejs/kit/node').GetRequest} */ export async function getRequest(base, req) { + let headers = /** @type {Record} */ (req.headers); + if (req.httpVersionMajor === 2) { + // we need to strip out the HTTP/2 pseudo-headers because node-fetch's + // Request implementation doesn't like them + headers = Object.assign({}, headers); + delete headers[':method']; + delete headers[':path']; + delete headers[':authority']; + delete headers[':scheme']; + } return new Request(base + req.url, { method: req.method, - headers: /** @type {Record} */ (req.headers), + headers, body: await get_raw_body(req) // TODO stream rather than buffer }); } From 15e734dac1714f02776fdd4cbd37e893a19446a0 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 27 Jan 2022 12:04:09 -0500 Subject: [PATCH 2/3] remove workaround forcing Vite to use HTTP/1 for dev mode --- packages/kit/src/core/dev/index.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/packages/kit/src/core/dev/index.js b/packages/kit/src/core/dev/index.js index a1e9a948e20b..3bcd1a9b1b54 100644 --- a/packages/kit/src/core/dev/index.js +++ b/packages/kit/src/core/dev/index.js @@ -85,14 +85,6 @@ export async function dev({ cwd, port, host, https, config }) { merged_config.server.https = https; } - // by default, when enabling HTTPS in Vite, it also enables HTTP/2 - // however, node-fetch's Request implementation does not like the HTTP/2 headers - // we set a no-op proxy config to force Vite to downgrade to TLS-only - // see https://vitejs.dev/config/#server-https - if (merged_config.server.https && !merged_config.server.proxy) { - merged_config.server.proxy = {}; - } - if (port) { merged_config.server.port = port; } From 814f5be98d85afa738caccd395ccc2d8652b6112 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 27 Jan 2022 12:05:04 -0500 Subject: [PATCH 3/3] add changeset --- .changeset/eight-readers-thank.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/eight-readers-thank.md diff --git a/.changeset/eight-readers-thank.md b/.changeset/eight-readers-thank.md new file mode 100644 index 000000000000..498b9f6a8857 --- /dev/null +++ b/.changeset/eight-readers-thank.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix handling an incoming request from HTTP/2