Skip to content

Honour qvalues when HttpContentCompressor selects the content encoding - #17726

Merged
normanmaurer merged 3 commits into
netty:4.2from
allthingssecurity:fix-http-content-compressor-qvalue-selection
Nov 5, 2026
Merged

normanmaurer merged 3 commits into
netty:4.2from
allthingssecurity:fix-http-content-compressor-qvalue-selection

Conversation

@allthingssecurity

@allthingssecurity allthingssecurity commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

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, ...). That pairwise rule was right when only gzip and deflate existed (determineWrapper(...)), but with five codings it picks a coding the client ranked lower, or did not accept at all:

Accept-Encoding configured selected now expected
br;q=0, gzip default, Brotli on the class path br gzip
gzip, br;q=0 default, Brotli on the class path br gzip
zstd;q=0, gzip default, zstd-jni on the class path zstd gzip
snappy;q=0, deflate default snappy deflate
br;q=0, zstd;q=0, snappy;q=0, gzip;q=0, deflate default, Brotli on the class path br deflate
br;q=0.1, gzip default, Brotli on the class path br gzip

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". A client that sends br;q=0 (for example because it cannot decode Brotli) gets a Brotli body it cannot decode.

The pairwise comparisons came with the additions of br (#11256), zstd (#11470) and snappy (#13529); the existing tests only cover single codings and equal qvalues.

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 (gzip, deflate and snappy configured, runs everywhere) and testDetermineEncodingHonoursQValuesBrotli (@EnabledIf("isBrotliAvailable")) as @ParameterizedTests.
  • Update HttpContentCompressorOptionsTest: "br; q=0, deflate" (and the same for zstd and snappy) now selects deflate, as the listed coding has qvalue 0.

Result:

The compressor no longer uses a content coding the client marked as not acceptable, and prefers the coding with the higher qvalue. Requests whose explicitly listed codings have equal qvalues, and requests that only use *, give the same result as before.

  • HttpContentCompressorTest, HttpContentEncoderTest, HttpContentDecompressorTest pass (63 tests), and HttpContentCompressorOptionsTest passes (4). Without the change to HttpContentCompressor, 7 of the 13 new cases fail; the others pass both ways.
  • Checkstyle and revapi pass.

The selection was also modelled in Lean 4 against the RFC 9110 rule: for every combination of qvalues from {absent, 0, 0.5, 1} for the five codings and *, and every subset of configured codings with qvalues from {absent, 0, 1}, the new selection only returns an acceptable coding with the highest qvalue, and it returns the same coding as before whenever the current result already satisfied that. The change was prepared with Claude Code (Claude Opus 5.5), and the commit has a Co-Authored-By trailer.

Prepared with Claude Code on behalf of allthingssecurity.

🤖 Generated with Claude Code

allthingssecurity and others added 3 commits October 2, 2026 07:34
Motivation:

HttpContentCompressor.determineEncoding(...) only compares each encoding
with the next one in the list br, zstd, snappy, gzip, deflate. So an
encoding is chosen although the client gave it a qvalue of 0 or a lower
qvalue than another encoding:

- "br;q=0, gzip" selects br (if Brotli is available)
- "snappy;q=0, deflate" selects snappy (the default options)
- "br;q=0.1, gzip" selects br

A qvalue of 0 means "not acceptable" (RFC 9110 12.4.2 and 12.5.3), so
the client may not be able to decode the response.

Modification:

Select the configured encoding with the highest qvalue above 0. If the
qvalues are equal, keep the existing preference order. The handling of
"*" is unchanged.

Result:

The compressor no longer uses an encoding the client did not accept, and
prefers the encoding with the higher qvalue.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Motivation:

HttpContentCompressorOptionsTest expected "br; q=0, deflate" (and the same
for zstd and snappy) to select the encoding that has a qvalue of 0. A
qvalue of 0 means "not acceptable" (RFC 9110 12.4.2), so with this change
deflate is selected.

Modification:

Expect deflate for "br; q=0, deflate", "zstd; q=0, deflate" and
"snappy; q=0, deflate".

Result:

The test matches the qvalue handling of HttpContentCompressor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allthingssecurity

Copy link
Copy Markdown
Contributor Author

Thanks for merging 4.2 in. The CI failures were in HttpContentCompressorOptionsTest: it expected "br; q=0, deflate" (and the same for zstd and snappy) to select the encoding with qvalue 0, which is the behaviour this PR changes (q=0 means "not acceptable", RFC 9110 12.4.2). a33b448 updates those three expectations to deflate. HttpContentCompressorOptionsTest (4) and HttpContentCompressorTest (39) pass locally with paranoid leak detection. Sorry for missing that class in the first run.

Prepared with Claude Code on behalf of allthingssecurity.

@testlens-app

testlens-app Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

🚨 Jobs failed without executing tests 🚨

Failed Jobs without Test Failures

❌ Build PR / macos-aarch64-java11-boringssl build

🏷️ Commit: a33b448
▶️ Tests: 0 executed
🟡 Checks: 30/33 completed

Rerun Controls

Click the checkbox to trigger a rerun:

🔲 Rerun jobs


Learn more about TestLens at testlens.app/docs.

@normanmaurer normanmaurer added this to the 4.2.20.Final milestone Oct 22, 2026
@chrisvest chrisvest modified the milestones: 4.2.20.Final, 4.2.21.Final Nov 2, 2026
@normanmaurer normanmaurer added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Nov 5, 2026
@normanmaurer
normanmaurer merged commit 5a638e4 into netty:4.2 Nov 5, 2026
30 of 31 checks passed
@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port PR for 5.0: #18285

@github-actions github-actions Bot removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Nov 5, 2026
@netty-project-bot

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 4.1.

@chrisvest

Copy link
Copy Markdown
Member

I'll try porting to 4.1

@chrisvest

Copy link
Copy Markdown
Member

4.1 port #18288

@chrisvest chrisvest removed the needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. label Nov 5, 2026
chrisvest pushed a commit that referenced this pull request Nov 5, 2026
…content encoding (#18285)

Auto-port of #17726 to 5.0
Cherry-picked commit: 5a638e4

---
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`, ...). That pairwise rule was right
when only gzip and deflate existed (`determineWrapper(...)`), but with
five codings it picks a coding the client ranked lower, or did not
accept at all:

| `Accept-Encoding` | configured | selected now | expected |
|---|---|---|---|
| `br;q=0, gzip` | default, Brotli on the class path | `br` | `gzip` |
| `gzip, br;q=0` | default, Brotli on the class path | `br` | `gzip` |
| `zstd;q=0, gzip` | default, zstd-jni on the class path | `zstd` |
`gzip` |
| `snappy;q=0, deflate` | default | `snappy` | `deflate` |
| `br;q=0, zstd;q=0, snappy;q=0, gzip;q=0, deflate` | default, Brotli on
the class path | `br` | `deflate` |
| `br;q=0.1, gzip` | default, Brotli on the class path | `br` | `gzip` |

[RFC 9110, Section
12.4.2](https://www.rfc-editor.org/rfc/rfc9110#section-12.4.2): "a value
of 0 means "not acceptable"", and [Section
12.5.3](https://www.rfc-editor.org/rfc/rfc9110#section-12.5.3): a listed
content coding is acceptable "unless it is accompanied by a qvalue of
0". A client that sends `br;q=0` (for example because it cannot decode
Brotli) gets a Brotli body it cannot decode.

The pairwise comparisons came with the additions of br (#11256), zstd
(#11470) and snappy (#13529); the existing tests only cover single
codings and equal qvalues.

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` (gzip, deflate and snappy
configured, runs everywhere) and
`testDetermineEncodingHonoursQValuesBrotli`
(`@EnabledIf("isBrotliAvailable")`) as `@ParameterizedTest`s.
- Update `HttpContentCompressorOptionsTest`: `"br; q=0, deflate"` (and
the same for zstd and snappy) now selects `deflate`, as the listed
coding has qvalue 0.

Result:

The compressor no longer uses a content coding the client marked as not
acceptable, and prefers the coding with the higher qvalue. Requests
whose explicitly listed codings have equal qvalues, and requests that
only use `*`, give the same result as before.

- `HttpContentCompressorTest`, `HttpContentEncoderTest`,
`HttpContentDecompressorTest` pass (63 tests), and
`HttpContentCompressorOptionsTest` passes (4). Without the change to
`HttpContentCompressor`, 7 of the 13 new cases fail; the others pass
both ways.
- Checkstyle and revapi pass.

The selection was also modelled in Lean 4 against the RFC 9110 rule: for
every combination of qvalues from {absent, 0, 0.5, 1} for the five
codings and `*`, and every subset of configured codings with qvalues
from {absent, 0, 1}, the new selection only returns an acceptable coding
with the highest qvalue, and it returns the same coding as before
whenever the current result already satisfied that. The change was
prepared with Claude Code (Claude Opus 5.5), and the commit has a
`Co-Authored-By` trailer.

_Prepared with Claude Code on behalf of allthingssecurity._

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: allthingssecurity <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
chrisvest added a commit that referenced this pull request Nov 6, 2026
…nt encoding (#17726) (#18288)

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.


(cherry picked from commit 5a638e4)

Co-authored-by: Norman Maurer <[email protected]>
ikpil added a commit to ikpil/Netty.NET that referenced this pull request Nov 29, 2026
…ent encoding (netty/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`, ...). That pairwise rule was right
when only gzip and deflate existed (`determineWrapper(...)`), but with
five codings it picks a coding the client ranked lower, or did not
accept at all:

| `Accept-Encoding` | configured | selected now | expected |
|---|---|---|---|
| `br;q=0, gzip` | default, Brotli on the class path | `br` | `gzip` |
| `gzip, br;q=0` | default, Brotli on the class path | `br` | `gzip` |
| `zstd;q=0, gzip` | default, zstd-jni on the class path | `zstd` |
`gzip` |
| `snappy;q=0, deflate` | default | `snappy` | `deflate` |
| `br;q=0, zstd;q=0, snappy;q=0, gzip;q=0, deflate` | default, Brotli on
the class path | `br` | `deflate` |
| `br;q=0.1, gzip` | default, Brotli on the class path | `br` | `gzip` |

[RFC 9110, Section
12.4.2](https://www.rfc-editor.org/rfc/rfc9110#section-12.4.2): "a value
of 0 means "not acceptable"", and [Section
12.5.3](https://www.rfc-editor.org/rfc/rfc9110#section-12.5.3): a listed
content coding is acceptable "unless it is accompanied by a qvalue of
0". A client that sends `br;q=0` (for example because it cannot decode
Brotli) gets a Brotli body it cannot decode.

The pairwise comparisons came with the additions of br (netty/netty#11256), zstd
(netty/netty#11470) and snappy (netty/netty#13529); the existing tests only cover single
codings and equal qvalues.

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` (gzip, deflate and snappy
configured, runs everywhere) and
`testDetermineEncodingHonoursQValuesBrotli`
(`@EnabledIf("isBrotliAvailable")`) as `@ParameterizedTest`s.
- Update `HttpContentCompressorOptionsTest`: `"br; q=0, deflate"` (and
the same for zstd and snappy) now selects `deflate`, as the listed
coding has qvalue 0.

Result:

The compressor no longer uses a content coding the client marked as not
acceptable, and prefers the coding with the higher qvalue. Requests
whose explicitly listed codings have equal qvalues, and requests that
only use `*`, give the same result as before.

---------

Co-authored-by: Norman Maurer <[email protected]>

Upstream-Commit: netty/netty@5a638e4
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.

4 participants