aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/http/cookies.py
diff options
context:
space:
mode:
authorShadab Zafar <dufferzafar0@gmail.com>2016-07-10 01:06:50 +0530
committerShadab Zafar <dufferzafar0@gmail.com>2016-07-10 01:06:50 +0530
commit39f51084003b93a2e9868f7a56acfc29c12ed79e (patch)
treef2c3c88baf77f843a492e938d6f612cdd9ff6f0e /netlib/http/cookies.py
parentc92992f03bba6553ec39fc42e6716beb942967e3 (diff)
downloadmitmproxy-39f51084003b93a2e9868f7a56acfc29c12ed79e.tar.gz
mitmproxy-39f51084003b93a2e9868f7a56acfc29c12ed79e.tar.bz2
mitmproxy-39f51084003b93a2e9868f7a56acfc29c12ed79e.zip
Test cookies.is_expired separately
Diffstat (limited to 'netlib/http/cookies.py')
-rw-r--r--netlib/http/cookies.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/netlib/http/cookies.py b/netlib/http/cookies.py
index 90789365..dd0af99c 100644
--- a/netlib/http/cookies.py
+++ b/netlib/http/cookies.py
@@ -262,23 +262,28 @@ def refresh_set_cookie_header(c, delta):
raise ValueError("Invalid Cookie")
return ret
+
def is_expired(cookie_attrs):
"""
Determines whether a cookie has expired.
Returns: boolean
"""
- expired = False
# See if 'expires' time is in the past
+ expires = False
if 'expires' in cookie_attrs:
e = email.utils.parsedate_tz(cookie_attrs["expires"])
if e:
exp_ts = email.utils.mktime_tz(e)
now_ts = time.time()
- expired = exp_ts < now_ts
+ expires = exp_ts < now_ts
# or if Max-Age is 0
- expired = expired or (int(cookie_attrs.get('Max-Age', 1)) == 0)
+ max_age = False
+ try:
+ max_age = int(cookie_attrs.get('Max-Age', 1)) == 0
+ except ValueError:
+ pass
- return expired
+ return expires or max_age