net/http: avoid redundant installation of HTTP/2 support in transport

Previously, we'd skip installing the bundled HTTP/2 support
if Transport.TLSNextProto is non-nil.

With the addition of the Transport.Protocols field, we'll
install HTTP/2 if Protocols contains HTTP2, even if TLSNextProto
is non-nil. However, we shouldn't do so if it already contains an
"h2" entry.

Change-Id: Ib086473bb52f1b76d83b1df961d41360c605832c
Reviewed-on: https://go-review.googlesource.com/c/go/+/631395
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
This commit is contained in:
Damien Neil 2024-11-22 17:10:01 -08:00 committed by Gopher Robot
parent 733df2bc0a
commit fb5fa2a839

View File

@ -412,6 +412,10 @@ func (t *Transport) onceSetNextProtoDefaults() {
} }
} }
if _, ok := t.TLSNextProto["h2"]; ok {
// There's an existing HTTP/2 implementation installed.
return
}
protocols := t.protocols() protocols := t.protocols()
if !protocols.HTTP2() && !protocols.UnencryptedHTTP2() { if !protocols.HTTP2() && !protocols.UnencryptedHTTP2() {
return return