Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[3.7] bpo-12144: Handle cookies with expires attribute in CookieJar.m…
…ake_cookies (GH-13921)

Handle time comparison for cookies with `expires` attribute when `CookieJar.make_cookies` is called.

Co-authored-by: Demian Brecht <demianbrecht@gmail.com>

https://bugs.python.org/issue12144

Automerge-Triggered-By: @asvetlov
(cherry picked from commit bb41147)

Co-authored-by: Xtreak <tir.karthi@gmail.com>
  • Loading branch information
tirkarthi committed Sep 13, 2019
commit ffc5ad02b3e467e1bf5a7d8593baaddc2bab1b66
3 changes: 1 addition & 2 deletions Lib/http/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,7 @@ def make_cookies(self, response, request):
headers = response.info()
rfc2965_hdrs = headers.get_all("Set-Cookie2", [])
ns_hdrs = headers.get_all("Set-Cookie", [])
self._policy._now = self._now = int(time.time())

rfc2965 = self._policy.rfc2965
netscape = self._policy.netscape
Expand Down Expand Up @@ -1669,8 +1670,6 @@ def extract_cookies(self, response, request):
_debug("extract_cookies: %s", response.info())
self._cookies_lock.acquire()
try:
self._policy._now = self._now = int(time.time())

for cookie in self.make_cookies(response, request):
if self._policy.set_ok(cookie, request):
_debug(" setting cookie: %s", cookie)
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_http_cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,15 @@ def test_expires(self):
# if expires is in future, keep cookie...
c = CookieJar()
future = time2netscape(time.time()+3600)

with test.support.check_no_warnings(self):
headers = [f"Set-Cookie: FOO=BAR; path=/; expires={future}"]
req = urllib.request.Request("http://www.coyote.com/")
res = FakeResponse(headers, "http://www.coyote.com/")
cookies = c.make_cookies(res, req)
self.assertEqual(len(cookies), 1)
self.assertEqual(time2netscape(cookies[0].expires), future)

interact_netscape(c, "http://www.acme.com/", 'spam="bar"; expires=%s' %
future)
self.assertEqual(len(c), 1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ensure cookies with ``expires`` attribute are handled in
:meth:`CookieJar.make_cookies`.