From 1efec481d0997e260f4524d45d11cc35bed63f73 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 18 May 2016 20:07:16 +0000 Subject: [PATCH] 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/23222 Reviewed-by: Andrew Gerrand Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/net/http/transport.go | 13 ++++++------- src/net/http/transport_test.go | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/net/http/transport.go b/src/net/http/transport.go index 865dbdd508..17e6270151 100644 --- a/src/net/http/transport.go +++ b/src/net/http/transport.go @@ -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 { diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index 48b1b309d3..ab05c31cb5 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -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 { -- 2.50.0