From 5414d1853e7526e6a8bb78b7916b83a7424027f9 Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Sat, 6 Feb 2021 10:58:36 +0100 Subject: [PATCH] Refactoring #1029 --- httpie/utils.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/httpie/utils.py b/httpie/utils.py index c1fde7cb..fddf15ad 100644 --- a/httpie/utils.py +++ b/httpie/utils.py @@ -109,14 +109,7 @@ 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) + _max_age_to_expires(cookies=cookies, now=now) return [ { @@ -126,3 +119,18 @@ def get_expired_cookies( for cookie in cookies if is_expired(expires=cookie.get('expires')) ] + + +def _max_age_to_expires(cookies, now): + """ + Translate `max-age` into `expires` for Requests to take it into account. + + HACK/FIXME: + + """ + 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)