diff --git a/api/client.go b/api/client.go index 5cd96280b90a..28bfc017fdb8 100644 --- a/api/client.go +++ b/api/client.go @@ -267,6 +267,9 @@ func NewClient(c *Config) (*Client, error) { if c.HttpClient == nil { c.HttpClient = DefaultConfig().HttpClient } + if c.HttpClient.Transport == nil { + c.HttpClient.Transport = cleanhttp.DefaultTransport() + } tp := c.HttpClient.Transport.(*http.Transport) if err := http2.ConfigureTransport(tp); err != nil { diff --git a/api/client_test.go b/api/client_test.go index 84663eea8885..2dc89a86aa06 100644 --- a/api/client_test.go +++ b/api/client_test.go @@ -37,6 +37,15 @@ func TestDefaultConfig_envvar(t *testing.T) { } } +func TestClientDefaultHttpClient(t *testing.T) { + _, err := NewClient(&Config{ + HttpClient: http.DefaultClient, + }) + if err != nil { + t.Fatal(err) + } +} + func TestClientNilConfig(t *testing.T) { client, err := NewClient(nil) if err != nil {