|
@@ -189,16 +189,15 @@ func NewClientWithOpts(ops ...Opt) (*Client, error) {
|
|
}
|
|
}
|
|
|
|
|
|
if c.scheme == "" {
|
|
if c.scheme == "" {
|
|
- c.scheme = "http"
|
|
|
|
-
|
|
|
|
- tlsConfig := resolveTLSConfig(c.client.Transport)
|
|
|
|
- if tlsConfig != nil {
|
|
|
|
- // TODO(stevvooe): This isn't really the right way to write clients in Go.
|
|
|
|
- // `NewClient` should probably only take an `*http.Client` and work from there.
|
|
|
|
- // Unfortunately, the model of having a host-ish/url-thingy as the connection
|
|
|
|
- // string has us confusing protocol and transport layers. We continue doing
|
|
|
|
- // this to avoid breaking existing clients but this should be addressed.
|
|
|
|
|
|
+ // TODO(stevvooe): This isn't really the right way to write clients in Go.
|
|
|
|
+ // `NewClient` should probably only take an `*http.Client` and work from there.
|
|
|
|
+ // Unfortunately, the model of having a host-ish/url-thingy as the connection
|
|
|
|
+ // string has us confusing protocol and transport layers. We continue doing
|
|
|
|
+ // this to avoid breaking existing clients but this should be addressed.
|
|
|
|
+ if c.tlsConfig() != nil {
|
|
c.scheme = "https"
|
|
c.scheme = "https"
|
|
|
|
+ } else {
|
|
|
|
+ c.scheme = "http"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -217,6 +216,16 @@ func defaultHTTPClient(hostURL *url.URL) (*http.Client, error) {
|
|
}, nil
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// tlsConfig returns the TLS configuration from the client's transport.
|
|
|
|
+// It returns nil if the transport is not a [http.Transport], or if no
|
|
|
|
+// TLSClientConfig is set.
|
|
|
|
+func (cli *Client) tlsConfig() *tls.Config {
|
|
|
|
+ if tr, ok := cli.client.Transport.(*http.Transport); ok {
|
|
|
|
+ return tr.TLSClientConfig
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
// Close the transport used by the client
|
|
// Close the transport used by the client
|
|
func (cli *Client) Close() error {
|
|
func (cli *Client) Close() error {
|
|
if t, ok := cli.client.Transport.(*http.Transport); ok {
|
|
if t, ok := cli.client.Transport.(*http.Transport); ok {
|
|
@@ -365,7 +374,7 @@ func (cli *Client) Dialer() func(context.Context) (net.Conn, error) {
|
|
case "npipe":
|
|
case "npipe":
|
|
return sockets.DialPipe(cli.addr, 32*time.Second)
|
|
return sockets.DialPipe(cli.addr, 32*time.Second)
|
|
default:
|
|
default:
|
|
- if tlsConfig := resolveTLSConfig(cli.client.Transport); tlsConfig != nil {
|
|
|
|
|
|
+ if tlsConfig := cli.tlsConfig(); tlsConfig != nil {
|
|
return tls.Dial(cli.proto, cli.addr, tlsConfig)
|
|
return tls.Dial(cli.proto, cli.addr, tlsConfig)
|
|
}
|
|
}
|
|
return net.Dial(cli.proto, cli.addr)
|
|
return net.Dial(cli.proto, cli.addr)
|