mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-05 07:37:50 +00:00
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
This commit is contained in:
parent
dddbaa803d
commit
7a61c26c8c
2 changed files with 26 additions and 1 deletions
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue