diff options
Diffstat (limited to 'util/request.go')
-rw-r--r-- | util/request.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/util/request.go b/util/request.go index c3227b7..12d2acb 100644 --- a/util/request.go +++ b/util/request.go @@ -10,7 +10,9 @@ import ( "time" ) -func RequestIP(requrl string, ip string, localAddr string) (string, error) { +func RequestIP(requrl string, ip string, localAddr string, proxyUrl string) (string, error) { + var proxy *url.URL + var err error if ip == "" { return "", errors.New("IP is empty") } @@ -23,11 +25,16 @@ func RequestIP(requrl string, ip string, localAddr string) (string, error) { ip = host } newrequrl := strings.Replace(requrl, host, ip, 1) + if proxyUrl != "" { + if proxy, err = url.Parse(proxyUrl); err != nil { + return "", errors.New("proxy parse error") + } + } + client := &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{ServerName: host}, - // goodryb pull - Proxy: http.ProxyFromEnvironment, + Proxy: http.ProxyURL(proxy), DialContext: (&net.Dialer{ LocalAddr: &net.TCPAddr{ IP: net.ParseIP(localAddr), |