Only call ConfigureTransport if "h2" is not already in NextProtos.

Fixes #3435
This commit is contained in:
Jeff Mitchell 2017-10-27 14:08:30 -04:00
parent 46afada06d
commit 08d9353c60
2 changed files with 26 additions and 2 deletions

View file

@ -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
}
}
}
}

View file

@ -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
}