From: Jes Cok Date: Mon, 26 Aug 2024 13:33:06 +0000 (+0000) Subject: net/http: simplify http.Request.Clone X-Git-Tag: go1.24rc1~1098 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=994d1d446663873dd593846a0b94147410e5922a;p=gostls13.git net/http: simplify http.Request.Clone By using maps.Clone and omitting nil checks when calling http.Header.Clone. I'm not using slices.Clone because the result of slices.Clone may have additional unused capacity. Change-Id: I4aed0fea218404c7270e35324e6bd62d855296c7 GitHub-Last-Rev: 9fd5dd59078c69c9a8057f6fc4a90f7c6aac893b GitHub-Pull-Request: golang/go#69070 Reviewed-on: https://go-review.googlesource.com/c/go/+/608295 Reviewed-by: Damien Neil Auto-Submit: Damien Neil Reviewed-by: Michael Pratt LUCI-TryBot-Result: Go LUCI --- diff --git a/src/net/http/request.go b/src/net/http/request.go index ad1b5a620b..686d53345a 100644 --- a/src/net/http/request.go +++ b/src/net/http/request.go @@ -15,6 +15,7 @@ import ( "errors" "fmt" "io" + "maps" "mime" "mime/multipart" "net/http/httptrace" @@ -390,12 +391,8 @@ func (r *Request) Clone(ctx context.Context) *Request { *r2 = *r r2.ctx = ctx r2.URL = cloneURL(r.URL) - if r.Header != nil { - r2.Header = r.Header.Clone() - } - if r.Trailer != nil { - r2.Trailer = r.Trailer.Clone() - } + r2.Header = r.Header.Clone() + r2.Trailer = r.Trailer.Clone() if s := r.TransferEncoding; s != nil { s2 := make([]string, len(s)) copy(s2, s) @@ -411,13 +408,7 @@ func (r *Request) Clone(ctx context.Context) *Request { copy(s2, s) r2.matches = s2 } - if s := r.otherValues; s != nil { - s2 := make(map[string]string, len(s)) - for k, v := range s { - s2[k] = v - } - r2.otherValues = s2 - } + r2.otherValues = maps.Clone(r.otherValues) return r2 }