]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: fix bug parsing http_proxy lacking a protocol
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 6 Dec 2012 03:08:42 +0000 (19:08 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 6 Dec 2012 03:08:42 +0000 (19:08 -0800)
Per the curl man page, the http_proxy configuration can be
of the form:

   [protocol://]<host>[:port]

And we had a test that <ip>:<port> worked, but if
the host began with a letter, url.Parse parsed the hostname
as the scheme instead, confusing ProxyFromEnvironment.

R=golang-dev
CC=golang-dev
https://golang.org/cl/6875060

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

index 48f7ac0e53553504ce3d40335655d4b2f061d5bf..068c50ff0ce48460a12285a3ba1878eb7dbf1a52 100644 (file)
@@ -90,7 +90,7 @@ func ProxyFromEnvironment(req *Request) (*url.URL, error) {
                return nil, nil
        }
        proxyURL, err := url.Parse(proxy)
-       if err != nil || proxyURL.Scheme == "" {
+       if err != nil || !strings.HasPrefix(proxyURL.Scheme, "http") {
                if u, err := url.Parse("http://" + proxy); err == nil {
                        proxyURL = u
                        err = nil
index e49f14fa581c22e1a5e91751bfa4c0a50b929750..0e6cf85281f44a15f58b1926d25bd9d1799ab132 100644 (file)
@@ -1068,6 +1068,9 @@ var proxyFromEnvTests = []struct {
        wanterr error
 }{
        {"127.0.0.1:8080", "http://127.0.0.1:8080", nil},
+       {"cache.corp.example.com:1234", "http://cache.corp.example.com:1234", nil},
+       {"cache.corp.example.com", "http://cache.corp.example.com", nil},
+       {"https://cache.corp.example.com", "https://cache.corp.example.com", nil},
        {"http://127.0.0.1:8080", "http://127.0.0.1:8080", nil},
        {"https://127.0.0.1:8080", "https://127.0.0.1:8080", nil},
        {"", "<nil>", nil},