Skip to content

Commit 0819ef0

Browse files
committed
Use http.DefaultTransport.Clone() when configuring proxy
When a proxy is configured, a bare http.Transport was created with only Proxy and optionally TLSClientConfig set. This Transport was missing all the defaults that http.DefaultTransport provides: TLSHandshakeTimeout, IdleConnTimeout, MaxIdleConns, ForceAttemptHTTP2, etc. Without a proxy, the client implicitly uses http.DefaultTransport with all these defaults. This created inconsistent behavior where proxy connections had no idle timeout, no TLS handshake timeout, and no HTTP/2 support. Clone http.DefaultTransport and overlay proxy settings on top so that proxy and non-proxy paths have equivalent transport behavior.
1 parent 3e20037 commit 0819ef0

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

ims/client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ func (i Config) httpClient() (*http.Client, error) {
1616
if err != nil {
1717
return nil, fmt.Errorf("proxy provided but its URL is malformed")
1818
}
19-
t := &http.Transport{
20-
Proxy: http.ProxyURL(p),
21-
}
19+
t := http.DefaultTransport.(*http.Transport).Clone()
20+
t.Proxy = http.ProxyURL(p)
2221
if i.ProxyIgnoreTLS {
2322
t.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
2423
}

0 commit comments

Comments
 (0)