mirror of
https://github.com/golang/go
synced 2024-11-22 03:14:41 -07:00
net/http: simplify http.Request.Clone
By using maps.Clone and omitting nil checks when calling Header.Clone(). I'm not using slices.Clone because the result of slices.Clone may have additional unused capacity. Change-Id: I6054b6091d2526975b0087abd86afa42412e90f2
This commit is contained in:
parent
96d8ff00c2
commit
9fd5dd5907
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user