Skip to content

Commit

Permalink
Don't expire cookie with later setting in the same headers
Browse files Browse the repository at this point in the history
  • Loading branch information
agriffis committed Jun 26, 2024
1 parent 5c068f8 commit 5753882
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
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

0 comments on commit 5753882

Please sign in to comment.