From bc8166c274736a2ef24ae85e0d86614e3381cf7d Mon Sep 17 00:00:00 2001 From: Will Chen Date: Mon, 19 May 2025 14:11:55 -0700 Subject: [PATCH] Fix proxy server injection for gzip content (#190) Some dev servers like next.js use Gzip which breaks our content injection so we avoid getting gzipped response when we need to do the shim injection. --- worker/proxy_server.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/worker/proxy_server.js b/worker/proxy_server.js index 1bccb2e..2d64a1b 100644 --- a/worker/proxy_server.js +++ b/worker/proxy_server.js @@ -181,6 +181,10 @@ const server = http.createServer((clientReq, clientRes) => { delete headers.referer; } } + if (needsInjection) { + // Request uncompressed content from upstream + delete headers["accept-encoding"]; + } if (headers["if-none-match"] && needsInjection(target.pathname)) delete headers["if-none-match"]; @@ -213,6 +217,11 @@ const server = http.createServer((clientReq, clientRes) => { ...upRes.headers, "content-length": Buffer.byteLength(patched), }; + // If we injected content, it's no longer encoded in the original way + delete hdrs["content-encoding"]; + // Also, remove ETag as content has changed + delete hdrs["etag"]; + clientRes.writeHead(upRes.statusCode, hdrs); clientRes.end(patched); } catch (e) {