Skip to content

net/http/httptest: ResponseRecorder.Result comment gives incorrect guarantee about ResponseRecorder.Body non-nil-ness #26442

Closed
@adam-p

Description

@adam-p

Please answer these questions before submitting your issue. Thanks!

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

1.10.3

Does this issue reproduce with the latest release?

Yes.

What did you do?

Compare the ResponseRecorder.Result documentation/comment...

// The Response.Body is guaranteed to be non-nil and Body.Read call is
// guaranteed to not return any error other than io.EOF.

...to actual behaviour:

if rw.Body != nil {
	res.Body = ioutil.NopCloser(bytes.NewReader(rw.Body.Bytes()))
}
...and then no case for when rw.Body _is_ nil...

It seems that guarantee doesn't apply if Response.Body was nil to begin with.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions