Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't expire cookie with later setting in the same headers #1584

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions httpie/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,14 @@ def is_expired(expires: Optional[float]) -> bool:
split_cookies(cookies)
)

cookies = [
# Use a dict to keep only the last value for each cookie, so that an early
# expiration doesn't prevent a later setting in the same headers.
cookies = {
# The first attr name is the cookie name.
dict(attrs[1:], name=attrs[0][0])
attrs[0][0]: dict(attrs[1:], name=attrs[0][0])
for attrs in attr_sets
]
}
cookies = list(cookies.values())

_max_age_to_expires(cookies=cookies, now=now)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,15 @@ def test_get_expired_cookies_using_max_age(self):
datetime(2020, 6, 11).timestamp(),
[]
),
(
# Don't expire cookie with later setting.
(
'session=; Path=/; Expires=Thu, 01-Jan-1970 00:00:00 GMT; secure; HttpOnly, '
'session=bar; Path=/; secure; HttpOnly'
),
None,
[]
)
]
)
def test_get_expired_cookies_manages_multiple_cookie_headers(self, cookies, now, expected_expired):
Expand Down
Loading