From 7a61c26c8cdba5029dbc06d1223bc5e25a201a9d Mon Sep 17 00:00:00 2001 From: Shivam Sharma <192242476+ShivamSharma43@users.noreply.github.com> Date: Mon, 26 Oct 2026 17:33:41 +0530 Subject: [PATCH] fix(proxy): read the Cache-Control request header again The proxy looked up "Cache-Control" in the cleaned header dict, whose keys are lowercase, so a client's s-maxage was never applied as the cache ttl. Read it from the case-insensitive request headers like before #22424 --- litellm/proxy/litellm_pre_call_utils.py | 2 +- .../unit/proxy/test_litellm_pre_call_utils.py | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.py index 8dc7501bc3b..abc6c656929 100644 --- a/litellm/proxy/litellm_pre_call_utils.py +++ b/litellm/proxy/litellm_pre_call_utils.py @@ -2606,7 +2606,7 @@ async def add_litellm_data_to_request( ) ## Cache Controls - cache_control_header: Final = _headers.get("Cache-Control", None) + cache_control_header: Final = request.headers.get("cache-control") if cache_control_header: cache_dict: Final = parse_cache_control(cache_control_header) data["ttl"] = cache_dict.get("s-maxage") diff --git a/tests/unit/proxy/test_litellm_pre_call_utils.py b/tests/unit/proxy/test_litellm_pre_call_utils.py index 64ff8392c02..ed4aeb72036 100644 --- a/tests/unit/proxy/test_litellm_pre_call_utils.py +++ b/tests/unit/proxy/test_litellm_pre_call_utils.py @@ -10645,3 +10645,28 @@ def test_mapped_baggage_tags_keep_non_string_client_tags_as_sent(): data: Final[dict[str, object]] = {"metadata": {"tags": [1, {"team": "x"}, "client-tag", "client-tag"]}} LiteLLMProxyRequestSetup.apply_authenticated_baggage_tags(request, data) assert data["metadata"]["tags"] == [1, {"team": "x"}, "client-tag", "client-tag", "tenant:a"] + + +@pytest.mark.asyncio +async def test_cache_control_s_maxage_header_sets_the_cache_ttl(): + from litellm.proxy.proxy_server import ProxyConfig + + request: Final = Request( + { + "type": "http", + "method": "POST", + "path": "/v1/chat/completions", + "scheme": "http", + "server": ("localhost", 4000), + "query_string": b"", + "headers": [(b"content-type", b"application/json"), (b"cache-control", b"s-maxage=10")], + } + ) + enriched: Final = await add_litellm_data_to_request( + data={"model": "qa-model", "messages": [{"role": "user", "content": "hi"}]}, + request=request, + user_api_key_dict=UserAPIKeyAuth(api_key="qa-key"), + proxy_config=ProxyConfig(), + general_settings={}, + ) + assert float(enriched["ttl"]) == 10