-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
proposal: net/http/cookiejar: add Jar.Clear #70258
Comments
Currently clearing all stored cookies puts a needless burden on package consumers, especially when used within http/Client where the calls to the cookiejar are not directly done by the consumer. This change just directly implements a safe clear of all entries. Fixes golang#70258
Change https://go.dev/cl/625898 mentions this issue: |
What's the use case of clearing everything? and is this the appropriate thing to do if you have in flight requests? |
My use case for it is making concurrent requests with an authenticated client until X time, at which point refreshing the auth cookies/tracking for the client. (And in this case inflight requests largely wouldn't matter, the cookies were either sent or weren't) |
that seems quite niche, and easily solvable by wrapping the stdlib implementation |
That's fair, my reason for proposal was just how trivial it is to implement within the cookie jar, while requiring additional mutexes and state tracking outside it. |
Proposal Details
Currently, since a jar's entries are not exposed to clear all cookies in a client's
Jar
in a thread-safe manner would require(from my understanding):Jar
is replaced with a new empty jar.Neither of those options are especially convenient, so I propose cookiejar adds a
Clear()
method that I will open a PR for. I am not proposing this is added tonet/http
'sCookieJar
as that would be a breaking change.The text was updated successfully, but these errors were encountered: