Commit 0c47bd1e authored by John Tuley's avatar John Tuley Committed by Brad Fitzpatrick

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
parent c7f6bd79
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment