aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/http/response.py
diff options
context:
space:
mode:
Diffstat (limited to 'netlib/http/response.py')
-rw-r--r--netlib/http/response.py44
1 files changed, 34 insertions, 10 deletions
diff --git a/netlib/http/response.py b/netlib/http/response.py
index 8af3c041..efd7f60a 100644
--- a/netlib/http/response.py
+++ b/netlib/http/response.py
@@ -1,6 +1,8 @@
from __future__ import absolute_import, print_function, division
import warnings
+from email.utils import parsedate_tz, formatdate, mktime_tz
+import time
from . import cookies
from .headers import Headers
@@ -94,6 +96,38 @@ class Response(Message):
values.append(header)
self.headers.set_all("set-cookie", values)
+ def refresh(self, now=None):
+ """
+ This fairly complex and heuristic function refreshes a server
+ response for replay.
+
+ - It adjusts date, expires and last-modified headers.
+ - It adjusts cookie expiration.
+ """
+ if not now:
+ now = time.time()
+ delta = now - self.timestamp_start
+ refresh_headers = [
+ "date",
+ "expires",
+ "last-modified",
+ ]
+ for i in refresh_headers:
+ if i in self.headers:
+ d = parsedate_tz(self.headers[i])
+ if d:
+ new = mktime_tz(d) + delta
+ self.headers[i] = formatdate(new)
+ c = []
+ for set_cookie_header in self.headers.get_all("set-cookie"):
+ try:
+ refreshed = cookies.refresh_set_cookie_header(set_cookie_header, delta)
+ except ValueError:
+ refreshed = set_cookie_header
+ c.append(refreshed)
+ if c:
+ self.headers.set_all("set-cookie", c)
+
# Legacy
def get_cookies(self): # pragma: no cover
@@ -103,13 +137,3 @@ class Response(Message):
def set_cookies(self, odict): # pragma: no cover
warnings.warn(".set_cookies is deprecated, use .cookies instead.", DeprecationWarning)
self.cookies = odict
-
- @property
- def msg(self): # pragma: no cover
- warnings.warn(".msg is deprecated, use .reason instead.", DeprecationWarning)
- return self.reason
-
- @msg.setter
- def msg(self, reason): # pragma: no cover
- warnings.warn(".msg is deprecated, use .reason instead.", DeprecationWarning)
- self.reason = reason