Skip to content

Handle comma-separated Content-Encoding in decode/encode - #8276

Open
clmoon2 wants to merge 2 commits into
mitmproxy:mainfrom
clmoon2:fix-2246-comma-content-encoding
Open

clmoon2 wants to merge 2 commits into
mitmproxy:mainfrom
clmoon2:fix-2246-comma-content-encoding

Conversation

@clmoon2

@clmoon2 clmoon2 commented Jun 7, 2026

Copy link
Copy Markdown

Content-Encoding can technically be a list like "sdch, gzip", and right now decode just does one dict lookup on the whole string and blows up with a KeyError/LookupError. so if a server sends something like that, decoding the body throws instead of working.

fixed it by splitting on commas and applying each codec in turn (reverse order for decode, forward for encode). also treat sdch as identity since we never actually decode it and it was the thing tripping people up here. went with handling it in encoding.py per the thread where mhils said we should just deal with this.

added a test covering the sdch, gzip case plus whitespace and casing, full suite passes locally. closes #2246

clmoon2 added 2 commits June 6, 2026 19:06
content-encoding can show up as a list like "sdch, gzip" and decode() was
just doing one dict lookup on the whole string which threw KeyError and then
a LookupError. now we split on commas and run each codec in order, reversed
for decode since that undoes them in the right order. sdch isn't something we
actually support so it just passes through like identity. fixes mitmproxy#2246.
individual_coverage was sitting at 99% cause the sdch no-op on encode
never got hit, only the decode one. add a quick assert for it.
@clmoon2

clmoon2 commented Jun 13, 2026

Copy link
Copy Markdown
Author

ci was just individual_coverage, the sdch no-op on the encode side never got exercised so encoding.py sat at 99%. added a one line assert covering it, green now

This branch has not been deployed

No deployments
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.

KeyError: 'sdch, gzip'

1 participant