mirror of
https://github.com/golang/go
synced 2024-11-23 04:30:03 -07:00
net/http: return nil from Header.Clone if the receiver is nil
Fixes #33141 Change-Id: I84a8b3496fc9396fd1c09ba9505697c34bdf7105 Reviewed-on: https://go-review.googlesource.com/c/go/+/188022 Run-TryBot: Andrew Bonventre <andybons@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
parent
39d4178735
commit
8dddf7556e
@ -78,8 +78,12 @@ func (h Header) write(w io.Writer, trace *httptrace.ClientTrace) error {
|
||||
return h.writeSubset(w, nil, trace)
|
||||
}
|
||||
|
||||
// Clone returns a copy of h.
|
||||
// Clone returns a copy of h or nil if h is nil.
|
||||
func (h Header) Clone() Header {
|
||||
if h == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Find total number of values.
|
||||
nv := 0
|
||||
for _, vv := range h {
|
||||
|
@ -176,6 +176,14 @@ func TestHasToken(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNilHeaderClone(t *testing.T) {
|
||||
t1 := Header(nil)
|
||||
t2 := t1.Clone()
|
||||
if t2 != nil {
|
||||
t.Errorf("cloned header does not match original: got: %+v; want: %+v", t2, nil)
|
||||
}
|
||||
}
|
||||
|
||||
var testHeader = Header{
|
||||
"Content-Length": {"123"},
|
||||
"Content-Type": {"text/plain"},
|
||||
|
Loading…
Reference in New Issue
Block a user