Skip to content

Preserve Accept-Encoding preferences when constraining supported codings - #8522

Closed
hakarrr wants to merge 5 commits into
mitmproxy:mainfrom
hakarrr:fix/preserve-accept-encoding-preferences
Closed

hakarrr wants to merge 5 commits into
mitmproxy:mainfrom
hakarrr:fix/preserve-accept-encoding-preferences

Conversation

@hakarrr

@hakarrr hakarrr commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Description

Request.constrain_encoding() currently searches for supported coding names as substrings, then rebuilds the header using bare names from a set. This changes the client's preferences:

  • gzip;q=0, br;q=0.5 becomes a header accepting gzip and dropping the relative preference.
  • GZIP, Br loses valid case-insensitive coding names.
  • xgzip, brotli, notzstd incorrectly advertises gzip, br and zstd.

Filter complete comma-separated members using their case-insensitive coding name, preserving each supported member's parameters, spelling and order. Keep explicit wildcard exclusions such as *;q=0, since removing one can make identity acceptable again. Positive wildcards remain removed so they cannot advertise unsupported codings.

RFC 9110 section 12.5.3 defines these weights and states that q=0 means not acceptable:
https://www.rfc-editor.org/rfc/rfc9110.html#section-12.5.3

This changes the explicit helper only, not default proxy behavior or Content-Encoding decoding. It is separate from #8276's stacked Content-Encoding handling.

Tests

Ten new cases cover quality weights, zero weights, casing, substring false positives, whitespace, wildcard exclusions/positive wildcard filtering, repeated header fields and an empty-header control. Eight fail against unchanged main 9125647; all ten pass with the fix. Existing missing-header and basic filtering tests also pass.

Validation in a separate exact-main tree, without #8518, #8520 or #8521 source changes:

  • 267 coretype, HTTP helper and HTTP model tests pass.
  • Broader Python run excluding tools: 1877 passed, 1 skipped, one TUN-device creation failure. The same TUN test fails against unchanged source in this environment.
  • Repository-wide Ruff checks pass; changed Python files are formatted.
  • Mypy: no issues in 253 source files.

No full tools suite, live proxy session or Windows/macOS run was performed.

Checklist

  • I have updated tests where applicable.
  • I have added an entry to the CHANGELOG.

@hakarrr

hakarrr commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

The remaining failed check here and on #8523 is the final autofix action's git step. The preceding lock, formatting, generated-file and lint steps pass. I can't access the job logs from this contributor account, so I can't tell whether a code change or maintainer action is needed.

Could you share the actual git error, or let me know what needs changing to get these ready for review? Grouping the question here rather than repeating it on both PRs. Thanks.

@hakarrr

hakarrr commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Could a maintainer advise on the next step for this Accept-Encoding fix? My earlier question about the autofix job's git error remains open. Please let me know whether author changes are needed before human review, or if you'd prefer the PR closed. Thanks.

@hakarrr hakarrr closed this Nov 17, 2026
@hakarrr
hakarrr deleted the fix/preserve-accept-encoding-preferences branch November 25, 2026 06:25
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