Skip to content

fix(mitmproxy): decompress response bodies based on content-encoding#47

Merged
Arkptz merged 1 commit into
mainfrom
fix/decompress-content-encoding
May 27, 2026
Merged

fix(mitmproxy): decompress response bodies based on content-encoding#47
Arkptz merged 1 commit into
mainfrom
fix/decompress-content-encoding

Conversation

@Arkptz
Copy link
Copy Markdown
Owner

@Arkptz Arkptz commented May 26, 2026

Root cause

mitmproxy v21 stores response bodies as raw wire bytes — still compressed per the content-encoding header. Our parser read them directly and passed compressed bytes to parse_body(), which tried serde_json::from_slice() on brotli/gzip data and silently returned None. Result: zero schemas emitted for any compressed response.

Fix

Added decompress_body(body: &[u8], encoding: Option<&str>) -> Vec<u8> helper that handles br (brotli), gzip, and deflate. On decompression failure it logs a warning and falls back to raw bytes for backward compatibility.

Applied to both request and response body extraction in parse_flow().

Test evidence

  • 5 new unit tests: brotli round-trip, gzip round-trip, deflate round-trip, invalid data fallback, no-encoding passthrough
  • cargo test: 240 passed, 0 failed
  • Real MEXC capture: grep -c "schema:" /tmp/fixed-spec.yaml → 2 (was 0), success field found in schema properties

Files changed

  • Cargo.toml: added brotli = "7" and flate2 = "1"
  • src/mitmproxy_reader.rs: decompress_body helper + applied at request/response extraction points

@Arkptz Arkptz merged commit 9f1e0c5 into main May 27, 2026
12 checks passed
@github-actions github-actions Bot mentioned this pull request May 27, 2026
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