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 <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
"errors"
"fmt"
"io"
+ "maps"
"mime"
"mime/multipart"
"net/http/httptrace"
*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)
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
}