encode / httpx

A next generation HTTP client for Python. 🦋

Home Page:https://www.python-httpx.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to override cookie policy

KKomarov opened this issue · comments

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:

Cookies(cookies).set_cookie_header(self)

self.jar = CookieJar()

When initialise request from existing cookies (which is Cookies object of Client), it discards policy object from source Cookies object.

if cookies or self.cookies:

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.