Repository navigation
Conversation
…abstack#3232) Signed-off-by: Sami Chergui <83331159+Yshuro@users.noreply.github.com>
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 @Yshuro for this fix to #3232. Review found a few gaps: malformed weights such as |
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.
Fixes #3232.
What
The Gzip middleware previously determined whether to compress responses using a substring match:
This caused two issues:
gzip;q=0was compressed even though the client explicitly disallowed gzip.custom-gziporother-gziptriggered compression because they contain the substringgzip.Fix
Replaced the substring check with token-aware parsing conforming to RFC 9110 Section 12.5.3:
q=...).gzip,GZIP).q=0as disallowing compression, whileq > 0allows it.*fallback, with explicitgzippreferences taking precedence (e.g.*;q=1, gzip;q=0disallows gzip,*;q=0, gzip;q=1allows gzip).Accept-Encodingheader fields viareq.Header.Values(echo.HeaderAcceptEncoding).Vary: Accept-Encodingresponse header in all cases.Tests
Added
TestGzip_AcceptEncodingQualitycovering 17 subtest scenarios andTestAcceptsGzip_EdgeCases. Full suite passes: