Skip to content

Commit

Permalink
Fix panic when setting a client http client with no transport
Browse files Browse the repository at this point in the history
Fixes #3436
  • Loading branch information
jefferai committed Oct 9, 2017
1 parent f034831 commit 6d55cc2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6d55cc2

Please sign in to comment.