]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: fix confusing shadowing in ProxyFromEnvironment
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 20 Jun 2013 18:58:24 +0000 (11:58 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 20 Jun 2013 18:58:24 +0000 (11:58 -0700)
The old code worked, somewhat on accident, but was confusing,
and had a useless assignment to the inner err. It worked
because url.Parse parses just about anything, so the outer err
was always nil, so it always fell through to the bottom return
statement, even without the "err = nil" line.

Instead, just have two return statements, and add a comment.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/10448044

src/pkg/net/http/transport.go

index 41ac7dea148a39cea6f922ad8483cc68bf361bcd..bd2106593b4dc81af03a3c5754e9c466a7195ef9 100644 (file)
@@ -109,9 +109,11 @@ func ProxyFromEnvironment(req *Request) (*url.URL, error) {
        }
        proxyURL, err := url.Parse(proxy)
        if err != nil || !strings.HasPrefix(proxyURL.Scheme, "http") {
-               if u, err := url.Parse("http://" + proxy); err == nil {
-                       proxyURL = u
-                       err = nil
+               // proxy was bogus. Try prepending "http://" to it and
+               // see if that parses correctly. If not, we fall
+               // through and complain about the original one.
+               if proxyURL, err := url.Parse("http://" + proxy); err == nil {
+                       return proxyURL, nil
                }
        }
        if err != nil {