Skip to content

fix: preserve aiohttp raw response headers#26895

Open
Genmin wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
Genmin:fix/aiohttp-nonascii-response-headers
Open

fix: preserve aiohttp raw response headers#26895
Genmin wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
Genmin:fix/aiohttp-nonascii-response-headers

Conversation

@Genmin

@Genmin Genmin commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • pass aiohttp raw_headers into httpx.Response so non-ASCII response header values are decoded by httpx from their original bytes
  • keep the existing decoded-header fallback for test/fake responses that do not expose raw_headers
  • add a regression covering a UTF-8 Chinese response header through LiteLLMAiohttpTransport

Fixes #26548.

Validation

  • /tmp/uv-0.10.9-env/bin/uv run --extra proxy pytest tests/test_litellm/test_streaming_connection_cleanup.py -q
  • /tmp/uv-0.10.9-env/bin/uv run --extra proxy black --check litellm/llms/custom_httpx/aiohttp_transport.py tests/test_litellm/test_streaming_connection_cleanup.py
  • /tmp/uv-0.10.9-env/bin/uv run --extra proxy ruff check litellm/llms/custom_httpx/aiohttp_transport.py tests/test_litellm/test_streaming_connection_cleanup.py
  • /tmp/uv-0.10.9-env/bin/uv run --extra proxy mypy litellm/llms/custom_httpx/aiohttp_transport.py
  • git diff --check -- litellm/llms/custom_httpx/aiohttp_transport.py tests/test_litellm/test_streaming_connection_cleanup.py

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes non-ASCII response header corruption in LiteLLMAiohttpTransport by passing aiohttp's raw_headers (raw bytes tuples) to httpx.Response instead of the pre-decoded headers dict, letting httpx handle decoding correctly. A fallback to response.headers is retained for test/fake responses that don't expose raw_headers.

Confidence Score: 5/5

Safe to merge — minimal, targeted fix with a focused regression test and no backwards-incompatible changes.

Single-line change using getattr with a safe fallback; the aiohttp raw_headers type (Tuple[Tuple[bytes, bytes], ...]) is a valid HeaderTypes input for httpx.Response, and the encoding path (httpx tries ASCII → UTF-8 → latin-1) correctly handles the UTF-8 Chinese characters in the regression test. No P0/P1 issues found.

No files require special attention.

Important Files Changed

Filename Overview
litellm/llms/custom_httpx/aiohttp_transport.py Single-line fix: passes raw_headers (bytes tuples) to httpx.Response instead of decoded headers, with fallback for objects lacking raw_headers.
tests/test_litellm/test_streaming_connection_cleanup.py Adds a regression test with a fake aiohttp session that exposes raw_headers containing UTF-8-encoded Chinese characters, verifying they round-trip correctly through the transport layer.

Reviews (1): Last reviewed commit: "fix: preserve aiohttp raw response heade..." | Re-trigger Greptile

@codecov

codecov Bot commented Apr 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Bojun-Vvibe added a commit to Bojun-Vvibe/oss-contributions that referenced this pull request Apr 30, 2026
… #26275

Second batch of drip-213 reviews:
- openai/codex#20465 derive PermissionProfile directly in test helper (merge-as-is)
- BerriAI/litellm#26895 preserve aiohttp raw response headers for UTF-8 (merge-as-is)
- BerriAI/litellm#26893 cache-read pricing in custom-cost path (merge-after-nits)
- google-gemini/gemini-cli#26275 preserve non-text parts through hook translator (merge-after-nits)
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.

[Bug]: AsyncHTTPHandler aiohttp transport fails on non-ASCII response headers

2 participants