Commit 8dddf755 authored by Andrew Bonventre's avatar Andrew Bonventre

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: default avatarEmmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
parent 39d41787
......@@ -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"},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment