Skip to content

Unable to override cookie policy #2946

@KKomarov

Description

@KKomarov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions