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 presents status codes that net/http will not send as sent #45353

Open
talglobus opened this issue Apr 2, 2021 · 2 comments
Open
Labels
Milestone

Comments

@talglobus
Copy link

@talglobus talglobus commented Apr 2, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

Applies to all operating systems and architectures

What did you do?

Used net/http/httptest to test a net/http server.

What did you expect to see?

Behavior from net/http/httptest accurately reflects that of net/http.

What did you see instead?

When an HTTP status code is provided to net/http's response.WriteHeader which is outside of the range 100 to 999, inclusive, a panic is documented to occur as intended behavior. This is documented here, which is called from response.WriteHeader.

When an HTTP status code is provided to net/http/httptest's response.WriteHeader, it is stored as successfully sent for later access regardless of whether the status code falls outside the 100 to 999 range. This is documented here.

The ResponseRecorder exposed by net/http/httptest is inconsistent with the net/http behavior it is designed to test.

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 10, 2021

Change https://golang.org/cl/308950 mentions this issue: net/http/httptest: check the HeaderCode when WriteHeader

@odeke-em odeke-em added this to the Backlog milestone Apr 12, 2021
@odeke-em odeke-em changed the title net/http: net/http/httptest presents status codes that net/http will not send as sent net/http/httptest presents status codes that net/http will not send as sent Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants