]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: ensured that proxy errors are returned by Transport.RoundTrip.
authorJohn Tuley <john@tuley.org>
Fri, 19 Sep 2014 15:28:38 +0000 (11:28 -0400)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 19 Sep 2014 15:28:38 +0000 (11:28 -0400)
Fixes #8755.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews, jtuley
https://golang.org/cl/136710044

src/net/http/transport.go
src/net/http/transport_test.go

index 527ed8bdd117490aa8451ba5e9943e2e2aaf3223..f1aab8587c1a47255156f8b54a86899e8abad915 100644 (file)
@@ -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
index 3460d690e35262ecd171b1e42c8c1caa2c48a459..bdfeba3626fccefebed4b186b5382211fcb37462 100644 (file)
@@ -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