mirror of
https://github.com/golang/go
synced 2024-11-26 03:17:57 -07:00
net/http: make use of maps.Clone for Transport.{Clone, RegisterProtocol}
Change-Id: I52b04a095bb64a3ce5edc7d1187e022909d4bf42
This commit is contained in:
parent
5858205831
commit
7a88af7f56
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user