Skip to content

Implement new style cookies. - #1312

Merged
isidentical merged 7 commits into
httpie:masterfrom
isidentical:redirects
Mar 7, 2022
Merged

Implement new style cookies.#1312
isidentical merged 7 commits into
httpie:masterfrom
isidentical:redirects

Conversation

@isidentical

Copy link
Copy Markdown
Contributor

This PR implements the discussed Host-based cookie policy.

@codecov-commenter

codecov-commenter commented Mar 7, 2022

Copy link
Copy Markdown

Codecov Report

Merging #1312 (751faf0) into master (4d7d6b6) will decrease coverage by 0.55%.
The diff coverage is 95.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1312      +/-   ##
==========================================
- Coverage   97.28%   96.72%   -0.56%     
==========================================
  Files          67       90      +23     
  Lines        4235     6537    +2302     
==========================================
+ Hits         4120     6323    +2203     
- Misses        115      214      +99     
Impacted Files Coverage Δ
tests/test_binary.py 100.00% <ø> (ø)
httpie/compat.py 31.11% <27.90%> (-68.89%) ⬇️
tests/conftest.py 77.14% <61.53%> (-9.82%) ⬇️
httpie/manager/__main__.py 82.35% <82.35%> (ø)
httpie/output/lexers/metadata.py 82.35% <82.35%> (ø)
httpie/output/lexers/http.py 86.36% <86.36%> (ø)
tests/test_ssl.py 92.66% <87.50%> (-2.28%) ⬇️
httpie/models.py 94.23% <90.00%> (-3.14%) ⬇️
httpie/manager/tasks.py 90.16% <90.16%> (ø)
tests/test_uploads.py 97.70% <92.59%> (-2.30%) ⬇️
... and 76 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b5623cc...751faf0. Read the comment docs.

@isidentical
isidentical merged commit 7509dd4 into httpie:master Mar 7, 2022
alutoin-cloudamite added a commit to alutoin-cloudamite/cli that referenced this pull request Jul 31, 2026
Completes the fix for httpie#998, which reported that a cookie carrying only
`Max-Age=0` (no `Expires`) was never removed from the session file. httpie#1029
addressed that by translating `max-age` into `expires` in
`_max_age_to_expires()`, gated on `max_age.isdigit()`.

`str.isdigit()` is False for any negative value, so `Max-Age=-1` still never
receives an `expires` key, is never recognised as expired by
`get_expired_cookies()`, and is never removed -- the same symptom httpie#998
described, for the other common deletion idiom. HTTPie keeps sending a cookie
the server has told it to delete.

RFC 6265 section 5.2.2: "If delta-seconds is less than or equal to zero, let
expiry-time be the earliest representable date and time."

Parse with `int()` instead, so negative deltas are honoured while unparseable
values are still ignored rather than raising -- note that a narrower fix such as
`max_age.lstrip('-').isdigit()` would make `int('--1')` throw, which the new
test pins. This matches the standard library, which parses `max-age` with
`int()` in `http.cookiejar`.

Also rewrites the docstring. It read `HACK/FIXME: <psf/requests#5743>`, but that
issue was declined as a no-op rather than fixed, so this is not a workaround
awaiting upstream removal. The docstring now records the RFC rule, and that the
function is only load-bearing for pre-3.1.0 session layouts: those stored
cookies as a domainless dict, so `http.cookiejar`'s `clear(domain, path, name)`
could not match them, whereas since 3.1.0 each cookie is bound to a domain
(httpie#1312) and the cookiejar removes expired ones by itself. Removing this function
therefore means dropping support for the old layout first.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
alutoin-cloudamite added a commit to alutoin-cloudamite/cli that referenced this pull request Jul 31, 2026
Completes the fix for httpie#998, which reported that a cookie carrying only
`Max-Age=0` (no `Expires`) was never removed from the session file. httpie#1029
addressed that by translating `max-age` into `expires` in
`_max_age_to_expires()`, gated on `max_age.isdigit()`.

`str.isdigit()` is False for any negative value, so `Max-Age=-1` still never
receives an `expires` key, is never recognised as expired by
`get_expired_cookies()`, and is never removed -- the same symptom httpie#998
described, for the other common deletion idiom. HTTPie keeps sending a cookie
the server has told it to delete.

RFC 6265 section 5.2.2: "If delta-seconds is less than or equal to zero, let
expiry-time be the earliest representable date and time."

Parse with `int()` instead, so negative deltas are honoured while unparseable
values are still ignored rather than raising -- note that a narrower fix such as
`max_age.lstrip('-').isdigit()` would make `int('--1')` throw, which the new
test pins. This matches the standard library, which parses `max-age` with
`int()` in `http.cookiejar`.

Also rewrites the docstring. It read `HACK/FIXME: <psf/requests#5743>`, but that
issue was declined as a no-op rather than fixed, so this is not a workaround
awaiting upstream removal. The docstring now records the RFC rule, and that the
function is only load-bearing for pre-3.1.0 session layouts: those stored
cookies as a domainless dict, so `http.cookiejar`'s `clear(domain, path, name)`
could not match them, whereas since 3.1.0 each cookie is bound to a domain
(httpie#1312) and the cookiejar removes expired ones by itself. Removing this function
therefore means dropping support for the old layout first.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants