diff options
author | Shadab Zafar <dufferzafar0@gmail.com> | 2016-07-08 14:16:29 +0530 |
---|---|---|
committer | Shadab Zafar <dufferzafar0@gmail.com> | 2016-07-09 22:20:25 +0530 |
commit | c92992f03bba6553ec39fc42e6716beb942967e3 (patch) | |
tree | cb2e13b56e2b68dc6db74235da59c4af5fa47b50 /netlib/http | |
parent | 6a746deff57d7283ee8440148b87ea16a672739a (diff) | |
download | mitmproxy-c92992f03bba6553ec39fc42e6716beb942967e3.tar.gz mitmproxy-c92992f03bba6553ec39fc42e6716beb942967e3.tar.bz2 mitmproxy-c92992f03bba6553ec39fc42e6716beb942967e3.zip |
Move cookie expiry detection to separate function
Diffstat (limited to 'netlib/http')
-rw-r--r-- | netlib/http/cookies.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/netlib/http/cookies.py b/netlib/http/cookies.py index 768a85df..90789365 100644 --- a/netlib/http/cookies.py +++ b/netlib/http/cookies.py @@ -1,7 +1,8 @@ import collections +import email.utils import re +import time -import email.utils from netlib import multidict """ @@ -260,3 +261,24 @@ def refresh_set_cookie_header(c, delta): if not ret: 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 + 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 + + # or if Max-Age is 0 + expired = expired or (int(cookie_attrs.get('Max-Age', 1)) == 0) + + return expired |