From 6b602c05bb81721dfc102b3f97112b2cf58d4d60 Mon Sep 17 00:00:00 2001 From: Offending Commit Date: Tue, 2 Jun 2026 13:28:32 -0500 Subject: [PATCH] fix(web): strip content-encoding from vite dev proxy responses undici fetch auto-decompresses the body, so re-sending the upstream content-encoding/length would cause ERR_CONTENT_DECODING_FAILED if Honcho gzips. Drop those and hop-by-hop headers when relaying. nginx is unaffected. --- packages/web/vite.config.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/web/vite.config.ts b/packages/web/vite.config.ts index 2fed9ed..4622347 100644 --- a/packages/web/vite.config.ts +++ b/packages/web/vite.config.ts @@ -61,8 +61,17 @@ function honchoApiProxy(): Plugin { body: ["GET", "HEAD"].includes(req.method ?? "") ? undefined : Buffer.concat(chunks), }); res.statusCode = upstreamRes.status; + // undici's fetch auto-decompresses the body, so the original + // content-encoding/length no longer describe what we re-send — + // drop those (and hop-by-hop headers) to avoid ERR_CONTENT_DECODING_FAILED. + const SKIP = new Set([ + "content-encoding", + "content-length", + "transfer-encoding", + "connection", + ]); upstreamRes.headers.forEach((v, k) => { - res.setHeader(k, v); + if (!SKIP.has(k.toLowerCase())) res.setHeader(k, v); }); res.end(Buffer.from(await upstreamRes.arrayBuffer())); } catch (e) {