Skip to content

Commit

Permalink
Only call ConfigureTransport if "h2" is not already in NextProtos.
Browse files Browse the repository at this point in the history
Fixes #3435
  • Loading branch information
jefferai committed Oct 27, 2017
1 parent ed1cbb0 commit 2afbbb3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
15 changes: 13 additions & 2 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,19 @@ func NewClient(c *Config) (*Client, error) {
}

if tp, ok := c.HttpClient.Transport.(*http.Transport); ok {
if err := http2.ConfigureTransport(tp); err != nil {
return nil, err
if tcc := tp.TLSClientConfig; tcc != nil {
var found bool
for _, proto := range tcc.NextProtos {
if proto == "h2" {
found = true
break
}
}
if !found {
if err := http2.ConfigureTransport(tp); err != nil {
return nil, err
}
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,16 @@ func TestClientNonTransportRoundTripper(t *testing.T) {
t.Fatal(err)
}
}

func TestClone(t *testing.T) {
client1, err1 := NewClient(nil)
if err1 != nil {
t.Fatalf("NewClient failed: %v", err1)
}
client2, err2 := client1.Clone()
if err2 != nil {
t.Fatalf("Clone failed: %v", err2)
}

_ = client2
}

0 comments on commit 2afbbb3

Please sign in to comment.