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: document when (RoundTripper).RoundTrip may return a nil *Response #37599

Open
bcmills opened this issue Mar 2, 2020 · 2 comments
Open
Labels
Documentation NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented Mar 2, 2020

(Factored out from #37598.)

The net/http.RoundTripper interface is currently ambiguous about what happens in case of errors.

Its documentation says:

    // RoundTrip executes a single HTTP transaction, returning
    // a Response for the provided Request.

but:

    // … RoundTrip must return err == nil if it obtained
    // a response, regardless of the response's HTTP status code.
    // A non-nil err should be reserved for failure to obtain a
    // response.

Unfortunately, it does not specify whether “failure to obtain a response” may correspond to a nil *Response, or only one that is only partially populated.

CC @bradfitz @rsc

@bcmills bcmills changed the title net/http: document whether (RoundTripper).RoundTrip is allowed to return a nil Response net/http: document whether (RoundTripper).RoundTrip is allowed to return a nil *Response Mar 2, 2020
@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 2, 2020
@bcmills bcmills added this to the Backlog milestone Mar 2, 2020
@bcmills
Copy link
Contributor Author

bcmills commented Mar 2, 2020

The answer appears to be that RoundTrip should return a nil *Response if (and only if) it returns a non-nil error.

go/src/net/http/client.go

Lines 252 to 257 in c436ead

resp, err = rt.RoundTrip(req)
if err != nil {
stopTimer()
if resp != nil {
log.Printf("RoundTripper returned a response & error; ignoring response")
}

@bcmills bcmills changed the title net/http: document whether (RoundTripper).RoundTrip is allowed to return a nil *Response net/http: document when (RoundTripper).RoundTrip return a nil *Response Mar 2, 2020
@bcmills bcmills changed the title net/http: document when (RoundTripper).RoundTrip return a nil *Response net/http: document when (RoundTripper).RoundTrip may return a nil *Response Mar 2, 2020
@gopherbot
Copy link

Change https://golang.org/cl/230740 mentions this issue: net/http: document when (RoundTripper).RoundTrip may return a nil *Response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants