Skip to content

Respect q=0 in gzip content negotiation#3028

Open
freakes wants to merge 1 commit into
labstack:masterfrom
freakes:fix/gzip-respect-accept-encoding-q0
Open

Respect q=0 in gzip content negotiation#3028
freakes wants to merge 1 commit into
labstack:masterfrom
freakes:fix/gzip-respect-accept-encoding-q0

Conversation

@freakes

@freakes freakes commented Jun 26, 2026

Copy link
Copy Markdown

Summary

Fix gzip middleware to respect q=0 values in the Accept-Encoding header.

Problem

According to RFC 9110, an encoding with q=0 is explicitly unacceptable. The current implementation does not respect this quality value and may enable gzip even when the client sends:

Accept-Encoding: gzip;q=0

Solution

Update the gzip negotiation logic to honor q=0 quality values and skip gzip when it is explicitly marked as unacceptable.

Testing

  • added a regression test covering Accept-Encoding: gzip;q=0
  • go test ./middleware

@aldas

aldas commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

which real-world client sends Accept-Encoding: gzip;q=0?

@aldas

aldas commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

similar PR #3021

@freakes

freakes commented Jun 29, 2026

Copy link
Copy Markdown
Author

@aldas
I don't know of a mainstream browser that sends gzip;q=0 by default.
My motivation was standards compliance, but there's also another issue with the current implementation: it uses a substring match, so values like x-gzip or supergzip also enable gzip even though they are different coding tokens.
Since Accept-Encoding is a structured header, I thought it would be better to match coding tokens explicitly rather than relying on strings.Contains.

@aldas

aldas commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Maybe this thing could be helper function that people that need this feature could use in Skipper function.

At the moment the client can opt out from gzip is by not sending gzip Accept-Encoding so doing all this "acrobatics" to support disabling gzip with Accept-Encoding: gzip;q=0 feels little bit overdoing it.

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.

2 participants