From: Brad Fitzpatrick Date: Thu, 6 Dec 2012 03:08:42 +0000 (-0800) Subject: net/http: fix bug parsing http_proxy lacking a protocol X-Git-Tag: go1.1rc2~1712 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a034fc9855b307ab5e9e5da04602823d6414f512;p=gostls13.git net/http: fix bug parsing http_proxy lacking a protocol Per the curl man page, the http_proxy configuration can be of the form: [protocol://][:port] And we had a test that : 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 --- diff --git a/src/pkg/net/http/transport.go b/src/pkg/net/http/transport.go index 48f7ac0e53..068c50ff0c 100644 --- a/src/pkg/net/http/transport.go +++ b/src/pkg/net/http/transport.go @@ -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 diff --git a/src/pkg/net/http/transport_test.go b/src/pkg/net/http/transport_test.go index e49f14fa58..0e6cf85281 100644 --- a/src/pkg/net/http/transport_test.go +++ b/src/pkg/net/http/transport_test.go @@ -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},