From 1d4c35f14ed69761f70ff8ffaea6771791098c57 Mon Sep 17 00:00:00 2001 From: Denis Belavin Date: Fri, 5 Feb 2021 14:32:42 +0300 Subject: [PATCH 1/5] Fix issue: #998 --- httpie/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/httpie/utils.py b/httpie/utils.py index 97c3c8aff1..c1fde7cbac 100644 --- a/httpie/utils.py +++ b/httpie/utils.py @@ -109,6 +109,15 @@ def is_expired(expires: Optional[float]) -> bool: 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'], From 8c116e8bc71c88d0a07c7091e9a54d2f003a3bfe Mon Sep 17 00:00:00 2001 From: Denis Belavin Date: Fri, 5 Feb 2021 14:36:34 +0300 Subject: [PATCH 2/5] Add test for issue: #998 --- tests/test_sessions.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_sessions.py b/tests/test_sessions.py index ea22a1ad87..f52c477c2e 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -345,6 +345,15 @@ def test_expired_cookies(self, httpbin): 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=[ From 1654d71cb7995f1140df56616268689cbdc5074d Mon Sep 17 00:00:00 2001 From: Denis Belavin Date: Fri, 5 Feb 2021 14:45:10 +0300 Subject: [PATCH 3/5] Add yourself to the authors, issue: #998 --- AUTHORS.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index 99468e5528..196bb3f177 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -38,5 +38,6 @@ Patches and ideas * `Edward Yang `_ * `Aleksandr Vinokurov `_ * `Jeff Byrnes `_ +* `Denis Belavin `_ From bcd67d14cbd915de07a74d9354521a172a183549 Mon Sep 17 00:00:00 2001 From: Denis Belavin Date: Fri, 5 Feb 2021 17:40:48 +0300 Subject: [PATCH 4/5] data of test with error > stdin --- tests/test_uploads.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_uploads.py b/tests/test_uploads.py index 05fb2001d7..878a530d31 100644 --- a/tests/test_uploads.py +++ b/tests/test_uploads.py @@ -237,6 +237,7 @@ def test_request_body_from_file_by_path_chunked(self, httpbin): HTTPBIN_WITH_CHUNKED_SUPPORT + '/post', '@' + FILE_PATH_ARG, ) + print(r) assert HTTP_OK in r assert 'Transfer-Encoding: chunked' in r assert '"Content-Type": "text/plain"' in r From d4e57b221e1d055064d27c721c4b91130e1e55bc Mon Sep 17 00:00:00 2001 From: Denis Belavin Date: Fri, 5 Feb 2021 17:49:01 +0300 Subject: [PATCH 5/5] Restored the test --- tests/test_uploads.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_uploads.py b/tests/test_uploads.py index 878a530d31..05fb2001d7 100644 --- a/tests/test_uploads.py +++ b/tests/test_uploads.py @@ -237,7 +237,6 @@ def test_request_body_from_file_by_path_chunked(self, httpbin): HTTPBIN_WITH_CHUNKED_SUPPORT + '/post', '@' + FILE_PATH_ARG, ) - print(r) assert HTTP_OK in r assert 'Transfer-Encoding: chunked' in r assert '"Content-Type": "text/plain"' in r