mirror of
https://github.com/golang/go
synced 2024-10-03 06:21:21 -06:00
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://]<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
This commit is contained in:
parent
08918ba438
commit
a034fc9855
@ -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
|
||||
|
@ -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},
|
||||
|
Loading…
Reference in New Issue
Block a user