@@ -90,33 +90,37 @@ type ClientOpts struct {
9090}
9191
9292func buildTransport (opts ClientOpts , flags * Flags ) http.RoundTripper {
93- var transport http.RoundTripper
94- {
95- tp := http .DefaultTransport .(* http.Transport ).Clone ()
93+ transport := http .DefaultTransport .(* http.Transport ).Clone ()
9694
97- if flags .insecureSkipVerify != nil && * flags .insecureSkipVerify {
98- tp .TLSClientConfig = & tls.Config {InsecureSkipVerify : true }
99- }
100-
101- if tp .TLSClientConfig == nil {
102- tp .TLSClientConfig = & tls.Config {}
103- }
95+ if flags .insecureSkipVerify != nil && * flags .insecureSkipVerify {
96+ transport .TLSClientConfig = & tls.Config {InsecureSkipVerify : true }
97+ }
10498
105- if opts . ProxyURL != nil || opts . ProxyPath != "" {
106- tp = withProxyTransport ( tp , opts . ProxyURL , opts . ProxyPath )
107- }
99+ if transport . TLSClientConfig == nil {
100+ transport . TLSClientConfig = & tls. Config {}
101+ }
108102
109- transport = tp
103+ if opts .ProxyURL != nil || opts .ProxyPath != "" {
104+ // Explicit SRC_PROXY configuration takes precedence.
105+ transport = withProxyTransport (transport , opts .ProxyURL , opts .ProxyPath )
106+ } else if proxyURL := envProxyURL (opts .EndpointURL .String ()); proxyURL != nil && proxyURL .Scheme == "https" {
107+ // For HTTPS proxies discovered via standard env vars, use our custom
108+ // dialer to force HTTP/1.1 for the CONNECT tunnel. Many proxy servers
109+ // don't support HTTP/2 CONNECT, which Go may negotiate via ALPN when
110+ // TLS-connecting to an https:// proxy.
111+ transport = withProxyTransport (transport , proxyURL , "" )
110112 }
113+ // For http:// and socks5:// proxies from standard env vars, the cloned
114+ // transport's default Proxy handles them correctly without intervention.
111115
116+ var rt http.RoundTripper = transport
112117 if opts .AccessToken == "" && opts .OAuthToken != nil {
113- transport = & oauth.Transport {
118+ rt = & oauth.Transport {
114119 Base : transport ,
115120 Token : opts .OAuthToken ,
116121 }
117122 }
118-
119- return transport
123+ return rt
120124}
121125
122126// envProxyURL resolves the proxy URL
0 commit comments