-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http/httptest: ResponseRecorder does not mimic real behavior of WriteHeader() #8857
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
Labels
Milestone
Comments
CL https://golang.org/cl/10373 mentions this issue. |
It's been requested that we fix this for the next release. Unfortunately the CL above was never updated so didn't make it into Go 1.6. |
CL https://golang.org/cl/20047 mentions this issue. |
CL https://golang.org/cl/23257 mentions this issue. |
gopherbot
pushed a commit
that referenced
this issue
May 19, 2016
In Go versions 1 up to and including Go 1.6, ResponseRecorder.HeaderMap was both the map that handlers got access to, and was the map tests checked their results against. That did not mimic the behavior of the real HTTP server (Issue #8857), so HeaderMap was changed to be a snapshot at the first write in https://golang.org/cl/20047. But that broke cases where the Handler never did a write (#15560), so revert the behavior. Instead, introduce the ResponseWriter.Result method, returning an *http.Response. It subsumes ResponseWriter.Trailers which was added for Go 1.7 in CL 20047. Result().Header now contains the correct answer, and HeaderMap is unchanged in behavior from previous Go releases, so we don't break people's tests. People wanting the correct behavior can use ResponseWriter.Result. Fixes #15560 Updates #8857 Change-Id: I7ea9b56a6b843103784553d67f67847b5315b3d2 Reviewed-on: https://go-review.googlesource.com/23257 Reviewed-by: Damien Neil <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: