summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Belavin <41421345+LuckyDenis@users.noreply.github.com>2021-02-06 12:50:34 +0300
committerGitHub <noreply@github.com>2021-02-06 10:50:34 +0100
commit3c07a2532647f64a4aaa7c729557fee5dcc2e182 (patch)
tree6a2dde34f02bb398f981693d12653617ddff5e20
parentcf78a12e46ced68003263f4f43cee8fac720aa2c (diff)
Add support for max-age=0 cookie expiry (#1029)
Close #998
-rw-r--r--AUTHORS.rst1
-rw-r--r--httpie/utils.py9
-rw-r--r--tests/test_sessions.py9
3 files changed, 19 insertions, 0 deletions
diff --git a/AUTHORS.rst b/AUTHORS.rst
index 99468e55..196bb3f1 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -38,5 +38,6 @@ Patches and ideas
* `Edward Yang <https://github.com/honorabrutroll>`_
* `Aleksandr Vinokurov <https://github.com/aleksandr-vin>`_
* `Jeff Byrnes <https://github.com/jeffbyrnes>`_
+* `Denis Belavin <https://github.com/LuckyDenis>`_
diff --git a/httpie/utils.py b/httpie/utils.py
index 97c3c8af..c1fde7cb 100644
--- a/httpie/utils.py
+++ b/httpie/utils.py
@@ -109,6 +109,15 @@ def get_expired_cookies(
for attrs in attr_sets
]
+ # HACK/FIXME: https://github.com/psf/requests/issues/5743
+ for cookie in cookies:
+ if 'expires' in cookie:
+ continue
+
+ max_age = cookie.get('max-age')
+ if max_age and max_age.isdigit():
+ cookie['expires'] = now + float(max_age)
+
return [
{
'name': cookie['name'],
diff --git a/tests/test_sessions.py b/tests/test_sessions.py
index ea22a1ad..f52c477c 100644
--- a/tests/test_sessions.py
+++ b/tests/test_sessions.py
@@ -345,6 +345,15 @@ class TestExpiredCookies(CookieTestBase):
assert 'cookie1' in updated_session['cookies']
assert 'cookie2' not in updated_session['cookies']
+ def test_get_expired_cookies_using_max_age(self):
+ headers = [
+ ('Set-Cookie', 'one=two; Max-Age=0; path=/; domain=.tumblr.com; HttpOnly')
+ ]
+ expected_expired = [
+ {'name': 'one', 'path': '/'}
+ ]
+ assert get_expired_cookies(headers, now=None) == expected_expired
+
@pytest.mark.parametrize(
argnames=['headers', 'now', 'expected_expired'],
argvalues=[