net/http: clarify use-cases of WithContext vs Clone on requests #53413
Labels
Documentation
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
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: