Skip to content

fix(middleware): fix Accept-Encoding matching in compress middleware#1114

Open
boatnoah wants to merge 2 commits into
go-chi:masterfrom
boatnoah:fix/match-accept-encoding
Open

fix(middleware): fix Accept-Encoding matching in compress middleware#1114
boatnoah wants to merge 2 commits into
go-chi:masterfrom
boatnoah:fix/match-accept-encoding

Conversation

@boatnoah

@boatnoah boatnoah commented Jun 24, 2026

Copy link
Copy Markdown

Fixes #1069

Summary

matchAcceptEncoding used substring matching, so values like bgzip could match gzip, and encodings explicitly rejected with q=0 were still selected.

Fix

Parse each Accept-Encoding item as an encoding token plus parameters, compare the token and q parameter name case-insensitively, and reject matches with a parsed quality value of 0 or lower.

This intentionally keeps the existing server-side encoder precedence and does not add wildcard or q-priority negotiation.

Tests

Added helper-level regression coverage for exact matching, substring false positives, whitespace, mixed-case tokens and parameters, q=0 / q=0.0, and multiple accepted encodings.

Added middleware-level cases for gzip;q=0 returning no encoding and falling back to deflate when available.

@boatnoah boatnoah force-pushed the fix/match-accept-encoding branch from 993338a to 0cb1898 Compare June 24, 2026 21:30
@boatnoah boatnoah changed the title fix(middleware): exact token matching and q=0 rejection in Accept-Encoding fix(middleware): fix Accept-Encoding matching in compress middleware Jun 24, 2026
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