Skip to content

Commit 1ca4759

Browse files
committed
use the parsed endpoint url and consolidate proxy handling because the proxy in the config is now the one gathered from either SRC_PROXY or the standard env variables
1 parent 9f08a43 commit 1ca4759

2 files changed

Lines changed: 8 additions & 27 deletions

File tree

cmd/src/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"flag"
7-
"fmt"
87
"io"
98
"log"
109
"net"

internal/api/api.go

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,16 @@ func buildTransport(opts ClientOpts, flags *Flags) http.RoundTripper {
100100
transport.TLSClientConfig = &tls.Config{}
101101
}
102102

103-
if opts.ProxyURL != nil || opts.ProxyPath != "" {
104-
// Explicit SRC_PROXY configuration takes precedence.
103+
if opts.ProxyPath != "" || (opts.ProxyURL != nil && opts.ProxyURL.Scheme == "https") {
104+
// Use our custom dialer for:
105+
// - unix socket proxies
106+
// - TLS=enabled proxies, to force HTTP/1.1 for the CONNECT tunnel.
107+
// Many TLS-enabled proxy servers don't support HTTP/2 CONNECT,
108+
// which Go may negotiate via ALPN, resulting in connection errors.
105109
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, "")
112110
}
113-
// For http:// and socks5:// proxies from standard env vars, the cloned
111+
112+
// For http:// and socks5:// proxies, the cloned
114113
// transport's default Proxy handles them correctly without intervention.
115114

116115
var rt http.RoundTripper = transport
@@ -123,23 +122,6 @@ func buildTransport(opts ClientOpts, flags *Flags) http.RoundTripper {
123122
return rt
124123
}
125124

126-
// envProxyURL resolves the proxy URL
127-
// from standard HTTP_PROXY/HTTPS_PROXY/NO_PROXY
128-
// environment variables for the given endpoint.
129-
// Returns nil if the endpoint is not a valid URL,
130-
// no proxy is configured, or the endpoint is excluded.
131-
func envProxyURL(endpoint string) *url.URL {
132-
u, err := url.Parse(endpoint)
133-
if err != nil || u.Scheme == "" || u.Host == "" {
134-
return nil
135-
}
136-
proxyURL, err := http.ProxyFromEnvironment(&http.Request{URL: u})
137-
if err != nil || proxyURL == nil {
138-
return nil
139-
}
140-
return proxyURL
141-
}
142-
143125
// NewClient creates a new API client.
144126
func NewClient(opts ClientOpts) Client {
145127
if opts.Out == nil {

0 commit comments

Comments
 (0)