Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discarding cookies in client session #957

Closed
tailhook opened this issue Jul 5, 2016 · 5 comments
Closed

Discarding cookies in client session #957

tailhook opened this issue Jul 5, 2016 · 5 comments
Labels

Comments

@tailhook
Copy link
Contributor

tailhook commented Jul 5, 2016

It looks like there is no good way to discard cookies after each request.

In previous versions of aiohttp I've just used aiohttp.request(connector=...) for requests, but it's deprecated now. And it looks like the only way to do connections is to make ClientSession.

But ClientSession has hardcoded cookie processing which I don't need at all. I supply Cookie header value to the client_session.request(). And it gots replaced as soon as first response returns Set-Cookie (I mean CookieJar replaces the header on the all following requests), as far as I can observe.

Currently, I can fix it by:

session._cookie_jar._cookies.clear()
session.request(...)

But it looks like too ugly and wrong.

The overall use case is similar to a simple proxy: I maintain multiple server connections and send requests to the backends using a single ClientSession (to maintain a single connection pool for all incoming connections). So CookieJar's implementation handling is just wrong for it.

Any good ideas how to achieve this using aiohttp?

@asvetlov
Copy link
Member

asvetlov commented Jul 7, 2016

You can replace session._cookie_jar._cookies.clear() with just session.cookies.clear().
As an option we may add new flag to ClientSession for disabling cookie processing.

@tailhook
Copy link
Contributor Author

tailhook commented Jul 7, 2016

You can replace session._cookie_jar._cookies.clear() with just session.cookies.clear().

Sorry missed that property.

As an option we may add new flag to ClientSession for disabling cookie processing.

Would be nice. Because I don't want to pay for call_later used for cookie tracking.

Alternatively, there might be an option to replace CookieJar class with some no-op class. But I'm not sure if there are any other use cases for that. Maybe storing cookies on disk/across processes?

@asvetlov
Copy link
Member

Fixed by #963

@tailhook
Copy link
Contributor Author

Looks great. Thanks!

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants