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

net/http/httptest: ResponseRecorder.WriteHeader documentation makes a claim that seems untrue #32144

Closed
dmitshur opened this issue May 19, 2019 · 1 comment
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dmitshur
Copy link
Contributor

The documentation of the httptest.ResponseRecorder.WriteHeader method says:

WriteHeader sets rw.Code. After it is called, changing rw.Header will not affect rw.HeaderMap.

The sentence in bold was added in CL 20047.

Either I don't understand it correctly, or it's not true:

https://play.golang.org/p/KTLurhi9OGH

Based on my understanding, I expected the second println to print map[Content-Type:[text/plain; charset=utf-8]], not map[Content-Type:[modified]].

/cc @bradfitz @cmarcelo

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 19, 2019
@dmitshur dmitshur added this to the Go1.13 milestone May 19, 2019
@gopherbot
Copy link

Change https://golang.org/cl/178058 mentions this issue: net/http/httptest: update docs, remove old inaccurate sentence

@dmitshur dmitshur added Documentation NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 19, 2019
dmitshur added a commit to shurcooL/home that referenced this issue Jun 16, 2019
In tests, use the Result method. It produces output more representative
of what the handler actually responded with, making tests more accurate.

In legacy non-test usage as a temporary buffer, use Header() method
instead of relying on directly setting the deprecated HeaderMap map.
It was deprecated primarily for test-focused usage, but it's still
deprecated, and makes tools report using it as a problem.

Updates golang/go#32136
Updates golang/go#32144
@golang golang locked and limited conversation to collaborators May 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants