mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net/http: verify RoundTripper invariants in the send function
Issue #37598 reports a nil-panic in *Client.send that can only occur if one of the RoundTripper invariants is violated. Unfortunately, that condition is currently difficult to diagnose: it manifests as a panic during a Response field access, rather than something the user can easily associate with an specific erroneous RoundTripper implementation. No test because the new code paths are supposed to be unreachable. Updates #37598 Change-Id: If0451e9c6431f6fab7137de43727297a80def05b Reviewed-on: https://go-review.googlesource.com/c/go/+/221818 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
acac535c3c
commit
12d02e7d8e
1 changed files with 6 additions and 0 deletions
|
|
@ -265,6 +265,12 @@ func send(ireq *Request, rt RoundTripper, deadline time.Time) (resp *Response, d
|
||||||
}
|
}
|
||||||
return nil, didTimeout, err
|
return nil, didTimeout, err
|
||||||
}
|
}
|
||||||
|
if resp == nil {
|
||||||
|
return nil, didTimeout, fmt.Errorf("http: RoundTripper implementation (%T) returned a nil *Response with a nil error", rt)
|
||||||
|
}
|
||||||
|
if resp.Body == nil {
|
||||||
|
return nil, didTimeout, fmt.Errorf("http: RoundTripper implementation (%T) returned a *Response with a nil Body", rt)
|
||||||
|
}
|
||||||
if !deadline.IsZero() {
|
if !deadline.IsZero() {
|
||||||
resp.Body = &cancelTimerBody{
|
resp.Body = &cancelTimerBody{
|
||||||
stop: stopTimer,
|
stop: stopTimer,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue