Repository navigation
Conversation
vishr
added a commit
that referenced
this pull request
Nov 20, 2026
…responses in Gzip (#3239) Accept-Encoding is now parsed per RFC 9110: gzip;q=0 and malformed weights refuse gzip, the wildcard is honored, x-gzip is treated as gzip, and substrings such as "notgzip" no longer match. Responses that already carry a Content-Encoding (for example from a reverse proxy) are passed through instead of being compressed twice. Content-Length is now removed only when the body is actually compressed or when an error response replaces an unwritten body. Also fixes Write reporting more bytes than it was given when the MinLength threshold is crossed, a truncated gzip stream when a handler only flushes, and error responses keeping a stale Content-Encoding. Fixes #3232 Fixes #2788 Supersedes #3234, #3237 Co-authored-by: Yshuro <83331159+Yshuro@users.noreply.github.com> Co-authored-by: Twiink <154496350+Twiink@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Thank you @Twiink for this fix and for confirming that #2788 still happens on current v5. The fix landed in #3239 together with the Accept-Encoding fix for #3232. It also covers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
With
GzipwrappingProxy, an upstreamContent-Encoding: gzipresponse is compressed again while still advertised as a single gzip stream. An upstream deflate response is also recompressed and relabeled. A client decoding once receives compressed bytes instead of the original payload.Bypass gzip when a response already has Content-Encoding, before this middleware starts writing its own compressed stream. Forward the original status, headers, bytes and flushes, and discard the unused compressor during cleanup. This preserves Content-Length and encoded HEAD metadata as well.
Validation: real loopback upstream + Echo v5 proxy + client with automatic decompression disabled, covering gzip/deflate with three MinLength settings. Four cases fail on unchanged master and two buffered controls pass; all six pass with the fix. Four additional handler cases cover explicit/implicit headers, flushing and header-only responses. Existing gzip cases and the complete race suite pass, as do vet, staticcheck, golint and formatting. The full suite used command-local empty proxy variables so its IPv6 loopback requests bypass this machine's outbound proxy.
Related #2788: this reproduces the reported behavior on current v5 master
f275a6b. The flush-only gzip completion fix in #3208 is independent and unchanged.