Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: Header.Clone behavior #33141

Closed
dsnet opened this issue Jul 16, 2019 · 3 comments
Closed

net/http: Header.Clone behavior #33141

dsnet opened this issue Jul 16, 2019 · 3 comments

Comments

@dsnet
Copy link
Member

@dsnet dsnet commented Jul 16, 2019

The Header.Clone method is being added in Go1.13. It's current behavior is to always allocate a map and return it even if the receiver is nil.

Thus:

h1 := http.Header(nil)
h2 := h1.Clone()
fmt.Println(h1 == nil) // true
fmt.Println(h2 == nil) // false

Is this behavior we want to go with? It seems more consistent for Clone to return nil if the receiver is also nil.

@dsnet dsnet added this to the Go1.13 milestone Jul 16, 2019
@dsnet dsnet changed the title net/http: Request.Clone behavior net/http: Header.Clone behavior Jul 17, 2019
@golang golang deleted a comment from gopherbot Jul 17, 2019
@andybons

This comment has been minimized.

Copy link
Member

@andybons andybons commented Jul 30, 2019

Agree. Will send a change.

@bsiegert

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Jul 30, 2019

Change https://golang.org/cl/188022 mentions this issue: net/http: return nil from Header.Clone if the receiver is nil

@odeke-em

This comment has been minimized.

Copy link
Member

@odeke-em odeke-em commented Jul 31, 2019

Good catch @dsnet! I agree that passing a nil header to Clone should also return a nil header and I'll review @andybons' CL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.