Commit graph

3 commits

Author SHA1 Message Date
Vish Ranganathan
9685e4c476 fix: strip accept-encoding from forwarded proxy headers
Edge proxies such as Cloudflare Workers inject accept-encoding values
(e.g. gzip, br, zstd) into every outbound request. When Headroom
forwarded these headers unchanged to OpenAI or Anthropic, the upstream
could respond with Brotli-encoded content. Because httpx does not
decompress brotli without the optional brotli package, the raw
compressed bytes reached the JSON parser, causing a UnicodeDecodeError
and a 502 response to the client.

Fix: pop accept-encoding before forwarding so httpx negotiates its own
encoding independently. Applied consistently across all four request
header construction sites:

- openai.py: chat completions handler
- openai.py: Responses API handler
- openai.py: generic passthrough handler
- anthropic.py: main messages handler (CCR continuation already had the strip)

Closes #135
2026-04-15 11:40:11 -07:00
pythoninthegrass
82f65990e7 Remove unused ProxyConfig import from compression tests
Fixes linting error F401 where ProxyConfig was imported but never used.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-14 20:27:08 -06:00
pythoninthegrass
876e8601cf Add tests for compression header removal fix
Test cases verify:
- Content-Encoding and Content-Length headers are correctly removed
- Response bodies are already decompressed by httpx
- Keeping compression headers causes length mismatch issues
- The fix doesn't break uncompressed responses

These tests will catch regressions of the ZlibError bug.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-14 20:03:14 -06:00