feat: add cookies and host_only_cookies properties to CookieJar#12174
Open
Br1an67 wants to merge 6 commits intoaio-libs:masterfrom
Open
feat: add cookies and host_only_cookies properties to CookieJar#12174Br1an67 wants to merge 6 commits intoaio-libs:masterfrom
Br1an67 wants to merge 6 commits intoaio-libs:masterfrom
Conversation
Add read-only properties to expose stored cookies with their full attributes (expires, domain, path, etc.). The cookies property returns a MappingProxyType for immutability, and host_only_cookies returns a frozenset. Fixes aio-libs#3951
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12174 +/- ##
=======================================
Coverage 98.78% 98.79%
=======================================
Files 128 128
Lines 45327 45388 +61
Branches 2405 2408 +3
=======================================
+ Hits 44777 44839 +62
Misses 390 390
+ Partials 160 159 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Dreamsorcerer
approved these changes
Mar 1, 2026
Member
Dreamsorcerer
left a comment
There was a problem hiding this comment.
Based on @bdraco's proposal, this looks good to me. I'll let him give it final sign-off.
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.
What do these changes do?
Add read-only
cookiesandhost_only_cookiesproperties toCookieJar(andAbstractCookieJar/DummyCookieJar) so users can access stored cookies with their full attributes (expires, domain, path, etc.) without relying on private_cookies/_host_only_cookies.cookiesreturnsMappingProxyType[tuple[str, str], SimpleCookie]— an immutable view of the internal cookie storagehost_only_cookiesreturnsfrozenset[tuple[str, str]]— a frozen copy of the host-only cookie setThis addresses the long-standing request to expose cookie metadata that
filter_cookies()intentionally strips (since the HTTPCookieheader does not include attributes likeexpires).Are there changes in behavior for the user?
Two new public read-only properties are available on
CookieJarandDummyCookieJar:jar.cookies— read-only mapping of(domain, path) -> SimpleCookiejar.host_only_cookies— frozen set of(domain, name)tuplesNo existing behavior is changed.
Is it a substantial burden for the maintainers to support this?
Minimal. The properties are thin wrappers (
MappingProxyType/frozenset) over existing internal state with no new data structures. TheMappingProxyTypeprevents direct mutation of the mapping, though the underlyingSimpleCookievalues are still mutable — this matches the trade-off discussed in the issue.Related issue number
Fixes #3951
Checklist
CONTRIBUTORS.txtCHANGES/folder