Skip to content

Port 4.1: Honour qvalues when HttpContentCompressor selects the content encoding (#17726) - #18288

Merged
chrisvest merged 1 commit into
netty:4.1from
chrisvest:4.1-port-pr-17726
Nov 6, 2026
Merged

chrisvest merged 1 commit into
netty:4.1from
chrisvest:4.1-port-pr-17726

Conversation

@chrisvest

Copy link
Copy Markdown
Member

Motivation:

HttpContentCompressor.determineEncoding(...) parses the qvalue of every coding in Accept-Encoding correctly, but then only compares each coding with the next one in the list br, zstd, snappy, gzip, deflate (brQ >= zstdQ, zstdQ >= snappyQ, ...). With five codings this picks a coding the client ranked lower, or did not accept at all (e.g. br;q=0, gzip selected br).

RFC 9110, Section 12.4.2: "a value of 0 means "not acceptable"", and Section 12.5.3: a listed content coding is acceptable "unless it is accompanied by a qvalue of 0".

Modification:

  • Select the configured coding with the highest qvalue above 0. If qvalues are equal, keep the existing order br, zstd, snappy, gzip, deflate (so "gzip, br" still gives br). The * handling and the parsing are unchanged.
  • Add testDetermineEncodingHonoursQValues and testDetermineEncodingHonoursQValuesBrotli as @ParameterizedTests.
  • Update HttpContentCompressorOptionsTest: "br; q=0, deflate" (and the same for zstd and snappy) now selects deflate.

Result:

The compressor no longer uses a content coding the client marked as not acceptable, and prefers the coding with the higher qvalue.

(cherry picked from commit 5a638e4)

netty#17726)

Motivation:

`HttpContentCompressor.determineEncoding(...)` parses the qvalue of
every coding in `Accept-Encoding` correctly, but then only compares each
coding with the next one in the list `br, zstd, snappy, gzip, deflate`
(`brQ >= zstdQ`, `zstdQ >= snappyQ`, ...). With five codings this picks a
coding the client ranked lower, or did not accept at all (e.g.
`br;q=0, gzip` selected `br`).

RFC 9110, Section 12.4.2: "a value of 0 means "not acceptable"", and
Section 12.5.3: a listed content coding is acceptable "unless it is
accompanied by a qvalue of 0".

Modification:

- Select the configured coding with the highest qvalue above 0. If
qvalues are equal, keep the existing order `br, zstd, snappy, gzip,
deflate` (so `"gzip, br"` still gives `br`). The `*` handling and the
parsing are unchanged.
- Add `testDetermineEncodingHonoursQValues` and
`testDetermineEncodingHonoursQValuesBrotli` as `@ParameterizedTest`s.
- Update `HttpContentCompressorOptionsTest`: `"br; q=0, deflate"` (and
the same for zstd and snappy) now selects `deflate`.

Result:

The compressor no longer uses a content coding the client marked as not
acceptable, and prefers the coding with the higher qvalue.

Co-authored-by: Norman Maurer <[email protected]>
(cherry picked from commit 5a638e4)
@testlens-app

testlens-app Bot commented Nov 6, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: cf7fc69
▶️ Tests: 98348 executed
⚪️ Checks: 18/18 completed


Learn more about TestLens at testlens.app/docs.

@chrisvest
chrisvest merged commit f567534 into netty:4.1 Nov 6, 2026
19 checks passed
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.

1 participant