]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: further restrict when Transport's automatic HTTP/2 happens
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 18 May 2016 20:07:16 +0000 (20:07 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 18 May 2016 20:53:43 +0000 (20:53 +0000)
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/23222
Reviewed-by: Andrew Gerrand <adg@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/net/http/transport.go
src/net/http/transport_test.go

index 865dbdd50824e01a5bb19da41c7ba950d3bc7bb7..17e6270151901fda907aa718f0d52bc7375e8f38 100644 (file)
@@ -195,13 +195,12 @@ func (t *Transport) onceSetNextProtoDefaults() {
                // Transport.
                return
        }
-       if t.TLSClientConfig != nil {
-               // Be conservative for now (for Go 1.6) at least and
-               // don't automatically enable http2 if they've
-               // specified a custom TLS config. Let them opt-in
-               // themselves via http2.ConfigureTransport so we don't
-               // surprise them by modifying their tls.Config.
-               // Issue 14275.
+       if t.TLSClientConfig != nil || t.Dial != nil || t.DialTLS != nil {
+               // Be conservative and don't automatically enable
+               // http2 if they've specified a custom TLS config or
+               // custom dialers. Let them opt-in themselves via
+               // http2.ConfigureTransport so we don't surprise them
+               // by modifying their tls.Config. Issue 14275.
                return
        }
        if t.ExpectContinueTimeout != 0 && t != DefaultTransport {
index 48b1b309d330b2e488d407ec792fbdf1c96a32f2..ab05c31cb55501dcc5d3f38cd584376d30f892b6 100644 (file)
@@ -2986,6 +2986,21 @@ func TestTransportAutomaticHTTP2_ExpectContinueTimeout(t *testing.T) {
        }, 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) {
        _, err := tr.RoundTrip(new(Request))
        if err == nil {