1
0
mirror of https://github.com/golang/go synced 2024-11-11 18:01:47 -07:00

net/http: make use of maps.Clone for Transport.{Clone, RegisterProtocol}

Not a big deal, maybe it's a bit clearer that it's cloning a map.

Change-Id: I7c85382a01df97d1f58109b2483061e6decdf03a
GitHub-Last-Rev: 7a88af7f56
GitHub-Pull-Request: golang/go#69357
Reviewed-on: https://go-review.googlesource.com/c/go/+/612015
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
Jes Cok 2024-09-09 16:26:41 +00:00 committed by Gopher Robot
parent af0c40311e
commit 77e42fdeaf

View File

@ -20,6 +20,7 @@ import (
"internal/godebug"
"io"
"log"
"maps"
"net"
"net/http/httptrace"
"net/http/internal/ascii"
@ -349,9 +350,9 @@ func (t *Transport) Clone() *Transport {
*t2.HTTP2 = *t.HTTP2
}
if !t.tlsNextProtoWasNil {
npm := map[string]func(authority string, c *tls.Conn) RoundTripper{}
for k, v := range t.TLSNextProto {
npm[k] = v
npm := maps.Clone(t.TLSNextProto)
if npm == nil {
npm = make(map[string]func(authority string, c *tls.Conn) RoundTripper)
}
t2.TLSNextProto = npm
}
@ -830,9 +831,9 @@ func (t *Transport) RegisterProtocol(scheme string, rt RoundTripper) {
if _, exists := oldMap[scheme]; exists {
panic("protocol " + scheme + " already registered")
}
newMap := make(map[string]RoundTripper)
for k, v := range oldMap {
newMap[k] = v
newMap := maps.Clone(oldMap)
if newMap == nil {
newMap = make(map[string]RoundTripper)
}
newMap[scheme] = rt
t.altProto.Store(newMap)