From a034fc9855b307ab5e9e5da04602823d6414f512 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 5 Dec 2012 19:08:42 -0800 Subject: [PATCH] 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 --- src/pkg/net/http/transport.go | 2 +- src/pkg/net/http/transport_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) 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},