Commit 1efec481 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: further restrict when Transport's automatic HTTP/2 happens

Make the temporary, conservative restrictions from rev 79d9f48c in Go
1.6 permanent, and also don't do automatic TLS if the user configured
a Dial or DialTLS hook. (Go 1.7 has Transport.Dialer instead, for
tweaking dialing parameters)

Fixes #14275

Change-Id: I5550d5c1e3a293e103eb4251a3685dc204a23941
Reviewed-on: https://go-review.googlesource.com/23222Reviewed-by: default avatarAndrew Gerrand <adg@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 12491979
...@@ -195,13 +195,12 @@ func (t *Transport) onceSetNextProtoDefaults() { ...@@ -195,13 +195,12 @@ func (t *Transport) onceSetNextProtoDefaults() {
// Transport. // Transport.
return return
} }
if t.TLSClientConfig != nil { if t.TLSClientConfig != nil || t.Dial != nil || t.DialTLS != nil {
// Be conservative for now (for Go 1.6) at least and // Be conservative and don't automatically enable
// don't automatically enable http2 if they've // http2 if they've specified a custom TLS config or
// specified a custom TLS config. Let them opt-in // custom dialers. Let them opt-in themselves via
// themselves via http2.ConfigureTransport so we don't // http2.ConfigureTransport so we don't surprise them
// surprise them by modifying their tls.Config. // by modifying their tls.Config. Issue 14275.
// Issue 14275.
return return
} }
if t.ExpectContinueTimeout != 0 && t != DefaultTransport { if t.ExpectContinueTimeout != 0 && t != DefaultTransport {
......
...@@ -2986,6 +2986,21 @@ func TestTransportAutomaticHTTP2_ExpectContinueTimeout(t *testing.T) { ...@@ -2986,6 +2986,21 @@ func TestTransportAutomaticHTTP2_ExpectContinueTimeout(t *testing.T) {
}, false) }, false)
} }
func TestTransportAutomaticHTTP2_Dial(t *testing.T) {
var d net.Dialer
testTransportAutoHTTP(t, &Transport{
Dial: d.Dial,
}, false)
}
func TestTransportAutomaticHTTP2_DialTLS(t *testing.T) {
testTransportAutoHTTP(t, &Transport{
DialTLS: func(network, addr string) (net.Conn, error) {
panic("unused")
},
}, false)
}
func testTransportAutoHTTP(t *testing.T, tr *Transport, wantH2 bool) { func testTransportAutoHTTP(t *testing.T, tr *Transport, wantH2 bool) {
_, err := tr.RoundTrip(new(Request)) _, err := tr.RoundTrip(new(Request))
if err == nil { if err == nil {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment