Skip to content

fix compress middleware: exact match and respect q=0 in Accept-Encoding#1074

Open
Emil-Ka wants to merge 1 commit intogo-chi:masterfrom
Emil-Ka:fix/compress-match-accept-encoding
Open

fix compress middleware: exact match and respect q=0 in Accept-Encoding#1074
Emil-Ka wants to merge 1 commit intogo-chi:masterfrom
Emil-Ka:fix/compress-match-accept-encoding

Conversation

@Emil-Ka
Copy link
Copy Markdown

@Emil-Ka Emil-Ka commented Apr 1, 2026

Fixes #1069

matchAcceptEncoding used strings.Contains which caused two bugs:

  1. Substring false positivesAccept-Encoding: br incorrectly matched encoding b, bgzip matched gzip
  2. q=0 ignored — per RFC 9110 §12.5.3, q=0 means the encoding is explicitly not acceptable, but strings.Contains("gzip;q=0", "gzip") returned true

Fix: parse the encoding token properly — split on ;, trim whitespace, exact-match the name, reject when q=0.

Added unit tests covering all edge cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compress middleware: matchAcceptEncoding uses substring match and ignores q=0

1 participant