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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user