fix(proxy-request): prevent double compression by removing Accept-Encoding header #87597
+9
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes an issue where rewrites acting as proxies can return
500 Internal Server Errorwhen running Next.js behind a reverse proxy in standalone production builds.The request is correctly received by Next.js, proxied upstream, and the upstream responds with
200, but the client still receives a500response when response compression is enabled.I already documented this behavior in PR #87244. That PR aims to fix the same 500 error when using rewrites as proxies, but through a different approach.
The issue still reproduced in this setup.
This PR fixes the problem by explicitly removing the
Accept-Encodingheader on proxied requests, preventing double compression when running behind a reverse proxy.#87244 (comment)
Research and Findings
During debugging, the following was observed:
proxyRequest200500Accept-Encodingor forcingidentityresolves the issueThis strongly indicates a double compression or content encoding mismatch when multiple reverse proxies are involved.
Changes
Accept-Encodingheader for proxied requests to prevent double compressionFixes
Fixes #87071