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.
This commit is contained in:
@@ -61,8 +61,17 @@ function honchoApiProxy(): Plugin {
|
|||||||
body: ["GET", "HEAD"].includes(req.method ?? "") ? undefined : Buffer.concat(chunks),
|
body: ["GET", "HEAD"].includes(req.method ?? "") ? undefined : Buffer.concat(chunks),
|
||||||
});
|
});
|
||||||
res.statusCode = upstreamRes.status;
|
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) => {
|
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()));
|
res.end(Buffer.from(await upstreamRes.arrayBuffer()));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user