Commit 2a931bad authored by Kunpei Sakai's avatar Kunpei Sakai Committed by Brad Fitzpatrick

net/http: rename DialerAndTLSConfigSupportsHTTP2 to ForceAttemptHTTP2

Transport.DialerAndTLSConfigSupportsHTTP2 was added just earlier
in CL 130256 but we thought of a better name moments after submitting.
ForceAttemptHTTP2 is shorter, more direct, and doesn't constrain what
we can use it with in the future.

Updates #14391
Updates #27011

Change-Id: Ie5fc71bafcbcaa1941b5d49f748b6d710503d477
Reviewed-on: https://go-review.googlesource.com/c/go/+/172299Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 8285c85f
...@@ -46,7 +46,7 @@ var DefaultTransport RoundTripper = &Transport{ ...@@ -46,7 +46,7 @@ var DefaultTransport RoundTripper = &Transport{
KeepAlive: 30 * time.Second, KeepAlive: 30 * time.Second,
DualStack: true, DualStack: true,
}).DialContext, }).DialContext,
DialerAndTLSConfigSupportsHTTP2: true, ForceAttemptHTTP2: true,
MaxIdleConns: 100, MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second, IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second, TLSHandshakeTimeout: 10 * time.Second,
...@@ -259,11 +259,11 @@ type Transport struct { ...@@ -259,11 +259,11 @@ type Transport struct {
nextProtoOnce sync.Once nextProtoOnce sync.Once
h2transport h2Transport // non-nil if http2 wired up h2transport h2Transport // non-nil if http2 wired up
// DialerAndTLSConfigSupportsHTTP2 controls whether HTTP/2 is enabled when a non-zero // ForceAttemptHTTP2 controls whether HTTP/2 is enabled when a non-zero
// TLSClientConfig or Dial, DialTLS or DialContext func is provided. By default, use of any those fields conservatively // TLSClientConfig or Dial, DialTLS or DialContext func is provided. By default, use of any those fields conservatively
// disables HTTP/2. To use a customer dialer or TLS config and still attempt HTTP/2 // disables HTTP/2. To use a customer dialer or TLS config and still attempt HTTP/2
// upgrades, set this to true. // upgrades, set this to true.
DialerAndTLSConfigSupportsHTTP2 bool ForceAttemptHTTP2 bool
} }
// h2Transport is the interface we expect to be able to call from // h2Transport is the interface we expect to be able to call from
...@@ -303,13 +303,13 @@ func (t *Transport) onceSetNextProtoDefaults() { ...@@ -303,13 +303,13 @@ func (t *Transport) onceSetNextProtoDefaults() {
// Transport. // Transport.
return return
} }
if !t.DialerAndTLSConfigSupportsHTTP2 && (t.TLSClientConfig != nil || t.Dial != nil || t.DialTLS != nil || t.DialContext != nil) { if !t.ForceAttemptHTTP2 && (t.TLSClientConfig != nil || t.Dial != nil || t.DialTLS != nil || t.DialContext != nil) {
// Be conservative and don't automatically enable // Be conservative and don't automatically enable
// http2 if they've specified a custom TLS config or // http2 if they've specified a custom TLS config or
// custom dialers. Let them opt-in themselves via // custom dialers. Let them opt-in themselves via
// http2.ConfigureTransport so we don't surprise them // http2.ConfigureTransport so we don't surprise them
// by modifying their tls.Config. Issue 14275. // by modifying their tls.Config. Issue 14275.
// However, if DialerAndTLSConfigSupportsHTTP2 is true, it overrides the above checks. // However, if ForceAttemptHTTP2 is true, it overrides the above checks.
return return
} }
t2, err := http2configureTransport(t) t2, err := http2configureTransport(t)
......
...@@ -3595,7 +3595,7 @@ func TestTransportAutomaticHTTP2(t *testing.T) { ...@@ -3595,7 +3595,7 @@ func TestTransportAutomaticHTTP2(t *testing.T) {
func TestTransportAutomaticHTTP2_DialerAndTLSConfigSupportsHTTP2AndTLSConfig(t *testing.T) { func TestTransportAutomaticHTTP2_DialerAndTLSConfigSupportsHTTP2AndTLSConfig(t *testing.T) {
testTransportAutoHTTP(t, &Transport{ testTransportAutoHTTP(t, &Transport{
DialerAndTLSConfigSupportsHTTP2: true, ForceAttemptHTTP2: true,
TLSClientConfig: new(tls.Config), TLSClientConfig: new(tls.Config),
}, true) }, true)
} }
......
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