Skip to content

Use http.DefaultTransport.Clone() when configuring proxy#62

Merged
telegrapher merged 1 commit into
mainfrom
fix/http-transport-defaults-with-proxy
Feb 25, 2026
Merged

Use http.DefaultTransport.Clone() when configuring proxy#62
telegrapher merged 1 commit into
mainfrom
fix/http-transport-defaults-with-proxy

Conversation

@telegrapher

Copy link
Copy Markdown
Collaborator

Fix HTTP Transport missing defaults when proxy is configured

When a proxy is configured, httpClient() created a bare http.Transport with only Proxy and optionally TLSClientConfig set:

t := &http.Transport{
    Proxy: http.ProxyURL(p),
}

This Transport was missing all the defaults that http.DefaultTransport provides:

  • TLSHandshakeTimeout (10s)
  • IdleConnTimeout (90s)
  • MaxIdleConns (100)
  • ForceAttemptHTTP2 (true)
  • ExpectContinueTimeout, MaxIdleConnsPerHost, etc.

Without a proxy, the client implicitly uses http.DefaultTransport with all these defaults. This meant proxy connections had no idle timeout, no TLS handshake timeout, and no HTTP/2 support — creating inconsistent behavior between proxy and non-proxy paths.

The fix clones http.DefaultTransport and overlays proxy settings on top, so both paths have equivalent transport behavior.

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.
@telegrapher
telegrapher merged commit b1c8a13 into main Feb 25, 2026
5 checks passed
@telegrapher
telegrapher deleted the fix/http-transport-defaults-with-proxy branch February 28, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants