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
net/http: Client doesn't correctly set cookies for all requests - patch attached #3511
Labels
Comments
Looks like a real bug. Client.Post should populate the request with cookies from its Jar. My fault. CL http://golang.org/cl/6013049/ is a bit less invasive than the supplied patch. |
Comment 2 by steven.hartland@multiplay.co.uk: Its less invasive but atm several code paths have duplicate code for no real reason. This is also fixed by moving all the cookie logic to once central place which produces a cleaner result. |
I think the original patch is fine, but we don't do code reviews or patch submissions here. Please use the process: http://golang.org/doc/contribute.html#Code_review It will also need tests. If you'd like me to take this over, let me know, otherwise I'll wait for a new version of this to be submitted through codereview. Labels changed: removed priority-triage. Owner changed to @bradfitz. Status changed to Accepted. |
Comment 4 by steven.hartland@multiplay.co.uk: I can submit it via that process but testing is it a bit of a problem as it requires a working cookiejar which the current code doesn't have. I have a working implementation here but its not ready for public consumption yet. Given this what's the best route to take, maybe extend the current blackhole cookiejar to simply prints out or stores everything it gets for testing purposes only? |
You don't need a "working" cookie jar for a test. Keep in mind that you're not writing an end-to-end test here, but rather just a unit test that verifies that the client is calling the right hooks on the jar at the right times. What I'd recommend: in the test file, define your own implementation of CookieJar there: type fakeJar struct { numSets, numGets int } func (j *fakeJar) SetCookies(u *url.URL, cookies []*Cookie) { j.numSets++ } func (j *fakeJar) Cookies(u *url.URL) []*Cookie { j.numGets++ return []*Cookie{ ... "fake-cookie": "fake-value" ... } } Then, just write a normal http test (using httptest.NewServer, etc) that makes a new Client using the *fakeJar, and do a Get, Post, Do (HEAD, PUT, etc), and verified that the httptest Handler gets the fake cookie and/or numSets / numGets increment as appropriate at the right times. |
http://golang.org/cl/6013049/ contains the tests (and a sub par fix to avoid breakage). I suggest reviewing CL 6013049 first, once the tests are in place Steven can submit his patch as a CL. |
This issue was closed by revision b4456df. Status changed to Fixed. |
bradfitz
pushed a commit
that referenced
this issue
May 11, 2015
««« backport 05fc2ee43b46 net/http: add cookies from jar to POST request. The main content of this CL is a test case checking the reported issue 3511 and a tiny fix for it. A subsequent CL will refactor the fix as proposed issue 3511. Fixes #3511. R=golang-dev, steven.hartland, bradfitz CC=golang-dev https://golang.org/cl/6013049 »»»
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by steven.hartland@multiplay.co.uk:
Attachments:
The text was updated successfully, but these errors were encountered: