Fix (#998): Will not expire/delete cookie from session when Set-Cookie only sets Max-Age=0 without Expires - #1029
Merged
Merged
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1029 +/- ##
==========================================
+ Coverage 95.55% 95.56% +0.01%
==========================================
Files 61 61
Lines 3937 3947 +10
==========================================
+ Hits 3762 3772 +10
Misses 175 175
Continue to review full report at Codecov.
|
Contributor
Author
|
It looks like there was a bug in the test environment. 😊 |
jkbrzt
requested changes
Feb 5, 2021
Member
|
Thanks, @luckydenis 🥧 |
Contributor
Author
|
@jakubroztocil, Thank you, I hope to participate in your wonderful project again ^_^ |
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. PR httpie#1029 addressed that by translating `max-age` into `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. 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 httpie#1335 the layout carries domain and path and the cookiejar removes expired cookies 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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
The reason why the
cookiestate information is lost is that when a response is received, the query library does not processmax-age=0. It was decided to report the problem to therequestscommunity and implement a temporary solution.Done:
make test-all