diff options
| author | Shadab Zafar <dufferzafar0@gmail.com> | 2016-08-08 12:55:04 +0530 | 
|---|---|---|
| committer | Shadab Zafar <dufferzafar0@gmail.com> | 2016-08-15 12:00:23 +0530 | 
| commit | 03e61170424bb92199cff22797135498d5ec8ce5 (patch) | |
| tree | 21df7a0f46e2688e75329d2973890f1517462537 /netlib/http | |
| parent | 55f1ffe0b100c9aa2a24b041a91091601ea4575d (diff) | |
| download | mitmproxy-03e61170424bb92199cff22797135498d5ec8ce5.tar.gz mitmproxy-03e61170424bb92199cff22797135498d5ec8ce5.tar.bz2 mitmproxy-03e61170424bb92199cff22797135498d5ec8ce5.zip | |
Add a function to get cookie expiration time
Diffstat (limited to 'netlib/http')
| -rw-r--r-- | netlib/http/cookies.py | 26 | 
1 files changed, 26 insertions, 0 deletions
| diff --git a/netlib/http/cookies.py b/netlib/http/cookies.py index 389dbb26..7f32eddf 100644 --- a/netlib/http/cookies.py +++ b/netlib/http/cookies.py @@ -269,6 +269,32 @@ def refresh_set_cookie_header(c, delta):      return ret +def get_expiration_ts(cookie_attrs): +    """ +        Determines the time when the cookie will be expired. + +        Considering both 'expires' and 'max-age' parameters. + +        Returns: timestamp of when the cookie will expire. +                 None, if no expiration time is set. +    """ +    if 'expires' in cookie_attrs: +        e = email.utils.parsedate_tz(cookie_attrs["expires"]) +        if e: +            return email.utils.mktime_tz(e) + +    elif 'max-age' in cookie_attrs: +        try: +            max_age = int(cookie_attrs['Max-Age']) +        except ValueError: +            pass +        else: +            now_ts = time.time() +            return now_ts + max_age + +    return None + +  def is_expired(cookie_attrs):      """          Determines whether a cookie has expired. | 
