Skip to content

Commit e699e3f

Browse files
committed
fix: support custom servers using HTTP/2 in production
1 parent b24d37e commit e699e3f

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

.changeset/shy-needles-warn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: support custom servers using HTTP/2 in production

packages/kit/src/exports/node/index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,29 @@ function get_raw_body(req, body_size_limit) {
106106
// TODO 3.0 make the signature synchronous?
107107
// eslint-disable-next-line @typescript-eslint/require-await
108108
export async function getRequest({ request, base, bodySizeLimit }) {
109+
// the Request constructor rejects headers with ':' in the name
110+
const headers = {
111+
.../** @type {Record<string, string>} */ (request.headers)
112+
};
113+
if (headers[':method']) {
114+
if (!headers.method) {
115+
headers.method = headers[':method'];
116+
}
117+
delete headers[':method'];
118+
}
119+
if (headers[':authority']) {
120+
if (!headers.host) {
121+
headers.host = headers[':authority'];
122+
}
123+
delete headers[':authority'];
124+
}
125+
delete headers[':path'];
126+
delete headers[':scheme'];
109127
return new Request(base + request.url, {
110128
// @ts-expect-error
111129
duplex: 'half',
112130
method: request.method,
113-
headers: /** @type {Record<string, string>} */ (request.headers),
131+
headers,
114132
body:
115133
request.method === 'GET' || request.method === 'HEAD'
116134
? undefined

packages/kit/src/exports/vite/index.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -349,22 +349,6 @@ async function kit({ svelte_config }) {
349349
* Stores the final config.
350350
*/
351351
configResolved(config) {
352-
// we search for this plugin by name because we can't detect it
353-
// since it doesn't directly modify the https config unlike the mkcert plugin
354-
const vite_basic_ssl = config.plugins.find(({ name }) => name === 'vite:basic-ssl');
355-
356-
// by default, when enabling HTTPS in Vite, it also enables HTTP/2
357-
// however, undici has not yet enabled HTTP/2 by default: https://github.com/nodejs/undici/issues/2750
358-
// we set a no-op proxy config to force Vite to downgrade to TLS-only
359-
// see https://vitejs.dev/config/#server-https
360-
if ((config.server.https || vite_basic_ssl) && !config.server.proxy) {
361-
config.server.proxy = {};
362-
}
363-
364-
if ((config.preview.https || vite_basic_ssl) && !config.preview.proxy) {
365-
config.preview.proxy = {};
366-
}
367-
368352
vite_config = config;
369353
}
370354
};

0 commit comments

Comments
 (0)