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 · May be fixed by #38741
Open

net/http: document when (RoundTripper).RoundTrip may return a nil *Response #37599

bcmills opened this issue Mar 2, 2020 · 2 comments · May be fixed by #38741

Comments

@bcmills
Copy link
Member

@bcmills 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 this to the Backlog milestone Mar 2, 2020
@bcmills
Copy link
Member Author

@bcmills 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

@gopherbot gopherbot commented Apr 29, 2020

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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.