mozillazg / request

A developer-friendly HTTP request library for Gopher.
https://godoc.org/github.com/mozillazg/request
MIT License
427 stars 40 forks source link

applyProxy() makes http/https/socks5 connection re-use impossible. #31

Open sinylei opened 5 years ago

sinylei commented 5 years ago

When you set a proxy, applyProxy will recreate a new Transport. So the connection pool cached in original Transport object will be discarded. So I changed applyProxy in request/proxy_go12.go as below and it works very well for me.

func applyProxy(a *Args) (err error) { if a.Proxy == "" { return nil }

u, err := url.Parse(a.Proxy)
if err != nil {
    return err
}
switch u.Scheme {
case "http", "https", "socks5":
    a.Client.Transport.(*http.Transport).Proxy = http.ProxyURL(u)
}
return

}

mozillazg commented 5 years ago

@sinylei Feel free to send a pull request.