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.
This commit is contained in:
Will Chen
2025-05-19 14:11:55 -07:00
committed by GitHub
parent 6e08bc5c62
commit bc8166c274

View File

@@ -181,6 +181,10 @@ const server = http.createServer((clientReq, clientRes) => {
delete headers.referer; delete headers.referer;
} }
} }
if (needsInjection) {
// Request uncompressed content from upstream
delete headers["accept-encoding"];
}
if (headers["if-none-match"] && needsInjection(target.pathname)) if (headers["if-none-match"] && needsInjection(target.pathname))
delete headers["if-none-match"]; delete headers["if-none-match"];
@@ -213,6 +217,11 @@ const server = http.createServer((clientReq, clientRes) => {
...upRes.headers, ...upRes.headers,
"content-length": Buffer.byteLength(patched), "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.writeHead(upRes.statusCode, hdrs);
clientRes.end(patched); clientRes.end(patched);
} catch (e) { } catch (e) {