@@ -71,7 +71,7 @@ type request struct {
7171
7272// ClientOpts encapsulates the options given to NewClient.
7373type ClientOpts struct {
74- Endpoint string
74+ EndpointURL * url. URL
7575 AccessToken string
7676 AdditionalHeaders map [string ]string
7777
@@ -98,38 +98,20 @@ func buildTransport(opts ClientOpts, flags *Flags) *http.Transport {
9898 transport .TLSClientConfig = & tls.Config {}
9999 }
100100
101- if opts .ProxyURL != nil || opts .ProxyPath != "" {
102- // Explicit SRC_PROXY configuration takes precedence.
101+ if opts .ProxyPath != "" || (opts .ProxyURL != nil && opts .ProxyURL .Scheme == "https" ) {
102+ // Use our custom dialer for:
103+ // - unix socket proxies
104+ // - TLS=enabled proxies, to force HTTP/1.1 for the CONNECT tunnel.
105+ // Many TLS-enabled proxy servers don't support HTTP/2 CONNECT,
106+ // which Go may negotiate via ALPN, resulting in connection errors.
103107 transport = withProxyTransport (transport , opts .ProxyURL , opts .ProxyPath )
104- } else if proxyURL := envProxyURL (opts .Endpoint ); proxyURL != nil && proxyURL .Scheme == "https" {
105- // For HTTPS proxies discovered via standard env vars, use our custom
106- // dialer to force HTTP/1.1 for the CONNECT tunnel. Many proxy servers
107- // don't support HTTP/2 CONNECT, which Go may negotiate via ALPN when
108- // TLS-connecting to an https:// proxy.
109- transport = withProxyTransport (transport , proxyURL , "" )
110108 }
111- // For http:// and socks5:// proxies from standard env vars, the cloned
109+
110+ // For http:// and socks5:// proxies, the cloned
112111 // transport's default Proxy handles them correctly without intervention.
113112 return transport
114113}
115114
116- // envProxyURL resolves the proxy URL
117- // from standard HTTP_PROXY/HTTPS_PROXY/NO_PROXY
118- // environment variables for the given endpoint.
119- // Returns nil if the endpoint is not a valid URL,
120- // no proxy is configured, or the endpoint is excluded.
121- func envProxyURL (endpoint string ) * url.URL {
122- u , err := url .Parse (endpoint )
123- if err != nil || u .Scheme == "" || u .Host == "" {
124- return nil
125- }
126- proxyURL , err := http .ProxyFromEnvironment (& http.Request {URL : u })
127- if err != nil || proxyURL == nil {
128- return nil
129- }
130- return proxyURL
131- }
132-
133115// NewClient creates a new API client.
134116func NewClient (opts ClientOpts ) Client {
135117 if opts .Out == nil {
@@ -149,7 +131,7 @@ func NewClient(opts ClientOpts) Client {
149131
150132 return & client {
151133 opts : ClientOpts {
152- Endpoint : opts .Endpoint ,
134+ EndpointURL : opts .EndpointURL ,
153135 AccessToken : opts .AccessToken ,
154136 AdditionalHeaders : opts .AdditionalHeaders ,
155137 Flags : flags ,
@@ -184,7 +166,7 @@ func (c *client) NewHTTPRequest(ctx context.Context, method, p string, body io.R
184166}
185167
186168func (c * client ) createHTTPRequest (ctx context.Context , method , p string , body io.Reader ) (* http.Request , error ) {
187- req , err := http .NewRequestWithContext (ctx , method , strings .TrimRight (c .opts .Endpoint , "/" )+ "/" + p , body )
169+ req , err := http .NewRequestWithContext (ctx , method , strings .TrimRight (c .opts .EndpointURL . String () , "/" )+ "/" + p , body )
188170 if err != nil {
189171 return nil , err
190172 }
@@ -359,6 +341,6 @@ func (r *request) curlCmd() (string, error) {
359341 s += fmt .Sprintf (" %s \\ \n " , shellquote .Join ("-H" , k + ": " + v ))
360342 }
361343 s += fmt .Sprintf (" %s \\ \n " , shellquote .Join ("-d" , string (data )))
362- s += fmt .Sprintf (" %s" , shellquote .Join (r .client .opts .Endpoint + "/.api/graphql" ))
344+ s += fmt .Sprintf (" %s" , shellquote .Join (r .client .opts .EndpointURL . String () + "/.api/graphql" ))
363345 return s , nil
364346}
0 commit comments