Unable to override cookie policy
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- python
- Domain
- backend, networking
Research direction
Start with the linked sections of httpx/_models.py around lines 334 and 1030, then inspect httpx/_client.py around line 400. Trace how CookieJar objects are copied and merged, including the MozillaCookieJar example. Done means a policy supplied by the client is preserved, while a request-level policy overrides it.
Written by the indexing model from the issue text.
Description
Originally opened by
@KKomarovon 2023-11-15 01:09:25 in encode/httpx
I would like to be able to override the cookie policy used by a Client when making a request. However, overriding the cookie policy on the cookie jar of the Client or of the Request object has had no effect. These lines of code explains why:
https://github.com/encode/httpx/blob/497b315fc7a0ca6a54c8ec6c929568abaf6efab1/httpx/_models.py#L334
https://github.com/encode/httpx/blob/497b315fc7a0ca6a54c8ec6c929568abaf6efab1/httpx/_models.py#L1030
When initialise request from existing cookies (which is Cookies object of Client), it discards policy object from source Cookies object.
https://github.com/encode/httpx/blob/497b315fc7a0ca6a54c8ec6c929568abaf6efab1/httpx/_client.py#L400
The cookie jars of both the client and the request are merged into a newly constructed CookieJar, discarding the policies of both.
What I expected to be able to do, and what isn't working currently, is something like the following:
cookie = MozillaCookieJar(filename='cookies.txt', policy=MyCookiePolicy())
cookie.load()
session = httpx.Client(headers=headers, cookies=cookie)
session.get(url)
In my opinion Policy from CookieJar in Client should not be discarded. When CookieJar object passed in request then policy from request should override policy from Client.
- Dominant language
- Python
- Stars
- 1.6k
- Forks
- 103
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 25
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pydantic/httpx2
-
Please revert aiter_bytes signature to AsyncIteratorMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
pydantic/httpx2#1158 · 2 comments ·
Maintainers usually reply within 1 day
-
Export AutoBackendMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
pydantic/httpx2#1131 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Mention header name error message for invalid header encodingsMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
pydantic/httpx2#864 · 3 comments ·
Maintainers usually reply within 1 day
-
Support DigestAuth with "x-www-authenticate" in first response headerPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
Similar issues
-
Email validation accepts a trailing newlinePossibly taken @marcello-pichini claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dbt-labs/spark-utils#51 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
bug frontend
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
vendrabuck/HERD#1419 ·
Maintainers usually reply within 1 day