Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(passthrough): strip Server/Date/Connection from upstream response headers

Yuneng Jiang356082319648
diff --git a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
index d582240395f..014ec83a4ba 100644
--- a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
+++ b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py
@@ -320,7 +320,20 @@ class HttpPassThroughEndpointHelpers(BasePassthroughUtils):
litellm_call_id: Optional[str] = None,
custom_headers: Optional[dict] = None,
) -> dict:
- excluded_headers = {"transfer-encoding", "content-encoding"}
+ # Exclude headers that uvicorn writes itself (server, date) and
+ # encoding/length headers that don't survive re-serialization.
+ # If we forward the upstream's Server header, uvicorn adds its
+ # own and strict HTTP parsers (e.g. aiohttp) reject the
+ # response with "Duplicate 'Server' header found".
+ excluded_headers = {
+ "transfer-encoding",
+ "content-encoding",
+ "content-length",
+ "server",
+ "date",
+ "connection",
+ "keep-alive",
+ }
return_headers = {
key: value
diff --git a/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py b/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py
index 4d8fc5683ad..97a21136198 100644
--- a/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py
+++ b/tests/test_litellm/proxy/pass_through_endpoints/test_pass_through_endpoints.py
@@ -2575,3 +2575,46 @@ async def test_multipart_passthrough_preserves_boundary():
# Verify the response
assert response.status_code == 200
async_client.request.assert_called_once()
+
+
+def test_get_response_headers_strips_server_and_date():
+ """Regression: forwarding the upstream's Server/Date headers causes
+ uvicorn to add its own and strict HTTP parsers (aiohttp) reject the
+ response with 'Duplicate Server header found'. The helper must strip
+ headers that the ASGI server writes itself."""
+ upstream_headers = httpx.Headers(
+ {
+ "server": "cloudflare",
+ "date": "Fri, 24 Apr 2026 23:26:19 GMT",
+ "content-type": "application/json",
+ "content-length": "123",
+ "transfer-encoding": "chunked",
+ "content-encoding": "gzip",
+ "connection": "keep-alive",
+ "keep-alive": "timeout=5",
+ "x-request-id": "req_abc",
+ "anthropic-ratelimit-requests-remaining": "100",
+ }
+ )
+
+ result = HttpPassThroughEndpointHelpers.get_response_headers(upstream_headers)
+
+ lowered_keys = {k.lower() for k in result}
+ for stripped in (
+ "server",
+ "date",
+ "content-length",
+ "transfer-encoding",
+ "content-encoding",
+ "connection",
+ "keep-alive",
+ ):
+ assert (
+ stripped not in lowered_keys
+ ), f"{stripped!r} must not be forwarded by passthrough"
+
+ # Application/business headers must still pass through.
+ lowered = {k.lower(): v for k, v in result.items()}
+ assert lowered["content-type"] == "application/json"
+ assert lowered["x-request-id"] == "req_abc"
+ assert lowered["anthropic-ratelimit-requests-remaining"] == "100"