summaryrefslogtreecommitdiff
path: root/requests_cache/session.py
diff options
context:
space:
mode:
authorManuel Eggimann <meggimann@iis.ee.ethz.ch>2021-11-29 14:59:57 +0100
committerManuel Eggimann <manuel.eggimann@gmail.com>2021-11-30 15:17:47 +0100
commitaa154a5f1e333730aed4869b08bd464a87cd7de3 (patch)
treecf80343e85c3c43bbaad17a3d9c667c6962e84d0 /requests_cache/session.py
parent0d26cb768d19c75c1f882b82f859358732e69058 (diff)
downloadrequests-cache-aa154a5f1e333730aed4869b08bd464a87cd7de3.tar.gz
Update CachedResponse headers with 304 response headers (RFC7234)
Diffstat (limited to 'requests_cache/session.py')
-rw-r--r--requests_cache/session.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/requests_cache/session.py b/requests_cache/session.py
index 2468bdb..f45b7c5 100644
--- a/requests_cache/session.py
+++ b/requests_cache/session.py
@@ -183,9 +183,15 @@ class CacheMixin(MIXIN_BASE):
logger.debug(
f'Response for URL {request.url} has not been modified; using cached response and updating expiration date.'
)
- # Update the cache expiration date. Since we performed validation,
+ # Update the cache expiration date and the headers (see RFC7234 4.3.4, p.18). Since we performed validation,
# the cache entry may be marked as fresh again.
- self.cache.save_response(cached_response, actions.cache_key, actions.expires)
+ cached_response.headers.update(response.headers)
+ # Since it is a 304 response we have to update cache control once again with combination of
+ # cached_response's and 304 response's Cache-Control directives.
+ response.headers = cached_response.headers
+ actions.update_from_response(response)
+ cached_response.expires = actions.expires
+ self.cache.save_response(cached_response, actions.cache_key, cached_response.expires)
return cached_response
else:
logger.debug(f'Skipping cache write for URL: {request.url}')