From 22f0e6a6aec6b8085450f5c68ecf9fc275f1e4d7 Mon Sep 17 00:00:00 2001 From: EXPLOSION Date: Mon, 11 Nov 2024 05:19:36 -0500 Subject: [PATCH] Tested fixes --- cachecontrol/controller.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cachecontrol/controller.py b/cachecontrol/controller.py index f826aec0..9c519b0e 100644 --- a/cachecontrol/controller.py +++ b/cachecontrol/controller.py @@ -277,9 +277,11 @@ def cached_request(self, request: PreparedRequest) -> HTTPResponse | Literal[Fal def conditional_headers(self, request: PreparedRequest) -> dict[str, str]: resp = self._load_from_cache(request) - new_headers = {} + if not resp: + return {} + with resp: + new_headers = {} - if resp: headers: CaseInsensitiveDict[str] = CaseInsensitiveDict(resp.headers) if "etag" in headers: @@ -288,7 +290,7 @@ def conditional_headers(self, request: PreparedRequest) -> dict[str, str]: if "last-modified" in headers: new_headers["If-Modified-Since"] = headers["Last-Modified"] - return new_headers + return new_headers def _cache_set( self,