mirror of
https://github.com/golang/go
synced 2024-11-26 20:11:26 -07:00
net/http: ensured that proxy errors are returned by Transport.RoundTrip.
Fixes #8755. LGTM=bradfitz R=bradfitz CC=golang-codereviews, jtuley https://golang.org/cl/136710044
This commit is contained in:
parent
c7f6bd795a
commit
0c47bd1e61
@ -316,7 +316,7 @@ func (t *Transport) connectMethodForRequest(treq *transportRequest) (cm connectM
|
||||
if t.Proxy != nil {
|
||||
cm.proxyURL, err = t.Proxy(treq.Request)
|
||||
}
|
||||
return cm, nil
|
||||
return cm, err
|
||||
}
|
||||
|
||||
// proxyAuth returns the Proxy-Authorization header to set
|
||||
|
@ -2136,6 +2136,24 @@ func TestTransportDialTLS(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test for issue 8755
|
||||
// Ensure that if a proxy returns an error, it is exposed by RoundTrip
|
||||
func TestRoundTripReturnsProxyError(t *testing.T) {
|
||||
badProxy := func(*http.Request) (*url.URL, error) {
|
||||
return nil, errors.New("errorMessage")
|
||||
}
|
||||
|
||||
tr := &Transport{Proxy: badProxy}
|
||||
|
||||
req, _ := http.NewRequest("GET", "http://example.com", nil)
|
||||
|
||||
_, err := tr.RoundTrip(req)
|
||||
|
||||
if err == nil {
|
||||
t.Error("Expected proxy error to be returned by RoundTrip")
|
||||
}
|
||||
}
|
||||
|
||||
func wantBody(res *http.Response, err error, want string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user