-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: clarify use-cases of WithContext vs Clone on requests #53413
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
Comments
cc @neild |
Change https://go.dev/cl/412778 mentions this issue: |
I don't see anything wrong with that usage of |
Thanks for the quick turnaround! |
I'm curious why |
for the same reason it is unexported:
|
@seankhliao thanks for your comment. |
The
http.Request
struct had aClone
method added in go 1.13, prompted by this issue: #23544. At that time, I believe the documentation forWithContext
was updated to suggest that most uses of that method could be replaced withClone
.However, that issue also had this follow-up exchange: #23544 (comment)
And @bradfitz responded:
And this has come up occasionally in Slack as well, with people writing very simple middleware that wrap
http.Handler
and just stick a value into the context on the request usingWithContext
. An extremely simple version, for whichClone
seems like overkill, might be:So this issue is mostly asking: is this usage of
WithContext
in this sort of middleware context correct, and furthermore can we augment theWithContext
documentation block to be less prescriptive thatClone
is the obvious way to go, and that there are plenty of value use-cases forWithContext
, especially when you're not looking to "reuse" the request to make a subsequent request?The text was updated successfully, but these errors were encountered: