Skip to content

feat: add cookies and host_only_cookies properties to CookieJar#12174

Open
Br1an67 wants to merge 6 commits intoaio-libs:masterfrom
Br1an67:feat/expose-cookiejar-cookies
Open

feat: add cookies and host_only_cookies properties to CookieJar#12174
Br1an67 wants to merge 6 commits intoaio-libs:masterfrom
Br1an67:feat/expose-cookiejar-cookies

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 1, 2026

What do these changes do?

Add read-only cookies and host_only_cookies properties to CookieJar (and AbstractCookieJar / DummyCookieJar) so users can access stored cookies with their full attributes (expires, domain, path, etc.) without relying on private _cookies / _host_only_cookies.

  • cookies returns MappingProxyType[tuple[str, str], SimpleCookie] — an immutable view of the internal cookie storage
  • host_only_cookies returns frozenset[tuple[str, str]] — a frozen copy of the host-only cookie set

This addresses the long-standing request to expose cookie metadata that filter_cookies() intentionally strips (since the HTTP Cookie header does not include attributes like expires).

Are there changes in behavior for the user?

Two new public read-only properties are available on CookieJar and DummyCookieJar:

  • jar.cookies — read-only mapping of (domain, path) -> SimpleCookie
  • jar.host_only_cookies — frozen set of (domain, name) tuples

No 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. The MappingProxyType prevents direct mutation of the mapping, though the underlying SimpleCookie values are still mutable — this matches the trade-off discussed in the issue.

Related issue number

Fixes #3951

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
  • Add a new news fragment into the CHANGES/ folder

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
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Mar 1, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 1, 2026

Merging this PR will not alter performance

✅ 59 untouched benchmarks


Comparing Br1an67:feat/expose-cookiejar-cookies (2be3132) with master (2d03bc4)

Open in CodSpeed

@codecov
Copy link

codecov bot commented Mar 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.79%. Comparing base (2d03bc4) to head (2be3132).
⚠️ Report is 3 commits behind head on master.
✅ All tests successful. No failed tests found.

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     
Flag Coverage Δ
CI-GHA 98.64% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.38% <100.00%> (+<0.01%) ⬆️
OS-Windows 96.75% <100.00%> (-0.01%) ⬇️
OS-macOS 97.63% <100.00%> (+<0.01%) ⬆️
Py-3.10.11 97.19% <100.00%> (+<0.01%) ⬆️
Py-3.10.19 97.66% <100.00%> (-0.01%) ⬇️
Py-3.11.14 97.86% <100.00%> (+<0.01%) ⬆️
Py-3.11.9 97.39% <100.00%> (-0.01%) ⬇️
Py-3.12.10 97.49% <100.00%> (+<0.01%) ⬆️
Py-3.12.12 97.96% <100.00%> (+<0.01%) ⬆️
Py-3.13.12 98.20% <100.00%> (-0.01%) ⬇️
Py-3.14.3 98.16% <100.00%> (+<0.01%) ⬆️
Py-3.14.3t 97.27% <100.00%> (+0.01%) ⬆️
Py-pypy3.11.13-7.3.20 97.30% <100.00%> (-0.01%) ⬇️
VM-macos 97.63% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 98.38% <100.00%> (+<0.01%) ⬆️
VM-windows 96.75% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Dreamsorcerer Dreamsorcerer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on @bdraco's proposal, this looks good to me. I'll let him give it final sign-off.

@Dreamsorcerer Dreamsorcerer requested a review from bdraco March 1, 2026 12:34
@Dreamsorcerer Dreamsorcerer added the backport-3.14 Trigger automatic backporting to the 3.14 release branch by Patchback robot label Mar 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-3.14 Trigger automatic backporting to the 3.14 release branch by Patchback robot bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CookieJar filter_cookies does not preserve expiration date

2 participants