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 `_ * `Aleksandr Vinokurov `_ * `Jeff Byrnes `_ +* `Denis Belavin `_ 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=[