Skip to content

Commit

Permalink
Merge pull request #1605 from chalstrick/fixProxy
Browse files Browse the repository at this point in the history
Allow usage of proxies even when contacting localhost
  • Loading branch information
technoweenie committed Oct 25, 2016
2 parents cbf91a9 + eb19771 commit ce8a5a9
Show file tree
Hide file tree
Showing 2 changed files with 5,647 additions and 15 deletions.
17 changes: 2 additions & 15 deletions httputil/proxy.go
@@ -1,7 +1,6 @@
package httputil

import (
"net"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -87,7 +86,8 @@ func canonicalAddr(url *url.URL) string {
// useProxy reports whether requests to addr should use a proxy,
// according to the NO_PROXY or no_proxy environment variable.
// addr is always a canonicalAddr with a host and port.
// Copied from "net/http".ProxyFromEnvironment in the go std lib.
// Copied from "net/http".ProxyFromEnvironment in the go std lib
// and adapted to allow proxy usage even for localhost.
func useProxy(no_proxy, addr string) bool {
if len(addr) == 0 {
return true
Expand All @@ -97,19 +97,6 @@ func useProxy(no_proxy, addr string) bool {
return false
}

host, _, err := net.SplitHostPort(addr)
if err != nil {
return false
}
if host == "localhost" {
return false
}
if ip := net.ParseIP(host); ip != nil {
if ip.IsLoopback() {
return false
}
}

addr = strings.ToLower(strings.TrimSpace(addr))
if hasPort(addr) {
addr = addr[:strings.LastIndex(addr, ":")]
Expand Down

0 comments on commit ce8a5a9

Please sign in to comment.