Merge pull request #3525 from tonyb486/bugfix-dateheader

Fix #3502 by using email.utils.formatdate's usegmt argument.
This commit is contained in:
Maximilian Hils 2019-07-17 22:43:14 +02:00 committed by GitHub
commit 69a3f77256
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 3 deletions

View File

@ -304,7 +304,7 @@ def refresh_set_cookie_header(c: str, delta: int) -> str:
e = email.utils.parsedate_tz(attrs["expires"]) e = email.utils.parsedate_tz(attrs["expires"])
if e: if e:
f = email.utils.mktime_tz(e) + delta f = email.utils.mktime_tz(e) + delta
attrs.set_all("expires", [email.utils.formatdate(f)]) attrs.set_all("expires", [email.utils.formatdate(f, usegmt=True)])
else: else:
# This can happen when the expires tag is invalid. # This can happen when the expires tag is invalid.
# reddit.com sends a an expires tag like this: "Thu, 31 Dec # reddit.com sends a an expires tag like this: "Thu, 31 Dec

View File

@ -186,7 +186,7 @@ class Response(message.Message):
d = parsedate_tz(self.headers[i]) d = parsedate_tz(self.headers[i])
if d: if d:
new = mktime_tz(d) + delta new = mktime_tz(d) + delta
self.headers[i] = formatdate(new) self.headers[i] = formatdate(new, usegmt=True)
c = [] c = []
for set_cookie_header in self.headers.get_all("set-cookie"): for set_cookie_header in self.headers.get_all("set-cookie"):
try: try:

View File

@ -148,7 +148,7 @@ class TestResponseUtils:
def test_refresh(self): def test_refresh(self):
r = tresp() r = tresp()
n = time.time() n = time.time()
r.headers["date"] = email.utils.formatdate(n) r.headers["date"] = email.utils.formatdate(n, usegmt=True)
pre = r.headers["date"] pre = r.headers["date"]
r.refresh(946681202) r.refresh(946681202)
assert pre == r.headers["date"] assert pre == r.headers["date"]