diff options
author | John Tuley <john@tuley.org> | 2014-09-19 11:28:38 -0400 |
---|---|---|
committer | John Tuley <john@tuley.org> | 2014-09-19 11:28:38 -0400 |
commit | 1a6be6763cdd63016a6342235bdc2f6658205293 (patch) | |
tree | dc46cc33d514b81f69bd4b0bc420555e2e8afc65 /src/net | |
parent | 0b464bc74c90cc6447bd74d12a24a2928a3bd9ab (diff) | |
download | go-1a6be6763cdd63016a6342235bdc2f6658205293.tar.gz |
net/http: ensured that proxy errors are returned by Transport.RoundTrip.
Fixes issue 8755.
LGTM=bradfitz
R=bradfitz
CC=golang-codereviews, jtuley
https://codereview.appspot.com/136710044
Committer: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/http/transport.go | 2 | ||||
-rw-r--r-- | src/net/http/transport_test.go | 18 |
2 files changed, 19 insertions, 1 deletions
diff --git a/src/net/http/transport.go b/src/net/http/transport.go index 527ed8bdd..f1aab8587 100644 --- a/src/net/http/transport.go +++ b/src/net/http/transport.go @@ -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 diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index 3460d690e..bdfeba362 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -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 |