@@ -11,10 +11,9 @@ import (
1111 "net/url"
1212)
1313
14- func applyProxy (transport * http.Transport , proxyURL * url.URL , proxyPath string ) (applied bool ) {
15- if proxyURL == nil && proxyPath == "" {
16- return false
17- }
14+ func NewProxyTransport (base * http.Transport , proxyURL * url.URL , proxyPath string ) * http.Transport {
15+ // Clone so that we don't change the original transport
16+ transport := base .Clone ()
1817
1918 handshakeTLS := func (ctx context.Context , conn net.Conn , addr string ) (net.Conn , error ) {
2019 // Extract the hostname (without the port) for TLS SNI
@@ -34,8 +33,6 @@ func applyProxy(transport *http.Transport, proxyURL *url.URL, proxyPath string)
3433 return tlsConn , nil
3534 }
3635
37- proxyApplied := false
38-
3936 if proxyPath != "" {
4037 dial := func (ctx context.Context , _ , _ string ) (net.Conn , error ) {
4138 d := net.Dialer {}
@@ -52,13 +49,11 @@ func applyProxy(transport *http.Transport, proxyURL *url.URL, proxyPath string)
5249 transport .DialTLSContext = dialTLS
5350 // clear out any system proxy settings
5451 transport .Proxy = nil
55- proxyApplied = true
5652 } else if proxyURL != nil {
5753 switch proxyURL .Scheme {
5854 case "socks5" , "socks5h" :
5955 // SOCKS proxies work out of the box - no need to manually dial
6056 transport .Proxy = http .ProxyURL (proxyURL )
61- proxyApplied = true
6257 case "http" , "https" :
6358 dial := func (ctx context.Context , network , addr string ) (net.Conn , error ) {
6459 // Dial the proxy
@@ -130,9 +125,8 @@ func applyProxy(transport *http.Transport, proxyURL *url.URL, proxyPath string)
130125 transport .DialTLSContext = dialTLS
131126 // clear out any system proxy settings
132127 transport .Proxy = nil
133- proxyApplied = true
134128 }
135129 }
136130
137- return proxyApplied
131+ return transport
138132}
0 commit comments