From 06a65e9c446df0c24169e9b227b4f23eddfdec40 Mon Sep 17 00:00:00 2001 From: Sameer Kankute Date: Thu, 26 Feb 2026 10:54:17 +0530 Subject: [PATCH] FIx test_read_request* --- litellm/proxy/common_utils/http_parsing_utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/common_utils/http_parsing_utils.py b/litellm/proxy/common_utils/http_parsing_utils.py index 8d179a9caed..04d46ecaeb8 100644 --- a/litellm/proxy/common_utils/http_parsing_utils.py +++ b/litellm/proxy/common_utils/http_parsing_utils.py @@ -143,7 +143,8 @@ def _safe_get_request_headers(request: Optional[Request]) -> dict: """ if request is None: return {} - cached = getattr(request.state, "_cached_headers", None) + state = getattr(request, "state", None) + cached = getattr(state, "_cached_headers", None) if cached is not None: return cached try: @@ -154,7 +155,8 @@ def _safe_get_request_headers(request: Optional[Request]) -> dict: ) headers = {} try: - request.state._cached_headers = headers + if state is not None: + state._cached_headers = headers except Exception: pass # request.state may not be available in all contexts return headers