summaryrefslogtreecommitdiff
path: root/requests_cache/models
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/models
parent0d26cb768d19c75c1f882b82f859358732e69058 (diff)
downloadrequests-cache-aa154a5f1e333730aed4869b08bd464a87cd7de3.tar.gz
Update CachedResponse headers with 304 response headers (RFC7234)
Diffstat (limited to 'requests_cache/models')
-rwxr-xr-xrequests_cache/models/response.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/requests_cache/models/response.py b/requests_cache/models/response.py
index 974d878..ec65034 100755
--- a/requests_cache/models/response.py
+++ b/requests_cache/models/response.py
@@ -2,6 +2,7 @@ from datetime import datetime, timedelta, timezone
from logging import getLogger
from typing import TYPE_CHECKING, List, Optional, Tuple, Union
+import attr
from attr import define, field
from requests import PreparedRequest, Response
from requests.cookies import RequestsCookieJar
@@ -46,9 +47,13 @@ class CachedResponse(Response):
self.raw.headers = HTTPHeaderDict(self.headers)
@classmethod
- def from_response(cls, original_response: Response, **kwargs):
- """Create a CachedResponse based on an original response object"""
- obj = cls(**kwargs)
+ def from_response(
+ cls, original_response: Union[Response, 'CachedResponse'], expires: datetime = None, **kwargs
+ ):
+ """Create a CachedResponse based on an original Response or another CachedResponse object"""
+ if isinstance(original_response, CachedResponse):
+ return attr.evolve(original_response, expires=expires)
+ obj = cls(expires=expires, **kwargs)
# Copy basic attributes
for k in Response.__attrs__: