Skip to content

net/http: net/http/httptest presents status codes that net/http will not send as sent #45352

Closed
@talglobus

Description

@talglobus

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions