Move cookie expiry detection to separate function
This commit is contained in:
parent
6a746deff5
commit
c92992f03b
|
@ -1,10 +1,8 @@
|
|||
from __future__ import absolute_import, print_function, division
|
||||
|
||||
import collections
|
||||
import email.utils
|
||||
import hashlib
|
||||
import re
|
||||
import time
|
||||
|
||||
from six.moves import http_cookiejar
|
||||
from six.moves import urllib
|
||||
|
@ -325,20 +323,7 @@ class StickyCookieState:
|
|||
dom_port_path = self.ckey(attrs, f)
|
||||
|
||||
if self.domain_match(f.request.host, dom_port_path[0]):
|
||||
|
||||
# See if 'expires' time is in the past
|
||||
expired = False
|
||||
if 'expires' in attrs:
|
||||
e = email.utils.parsedate_tz(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(attrs.get('Max-Age', 1)) == 0)
|
||||
|
||||
if expired:
|
||||
if cookies.is_expired(attrs):
|
||||
# Remove the cookie from jar
|
||||
self.jar[dom_port_path].pop(name, None)
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import collections
|
||||
import re
|
||||
|
||||
import email.utils
|
||||
import re
|
||||
import time
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue