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 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; } 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 }); }