Basically, my suggestion is to check if the incoming ctx and the existing r.ctx point to the same value in memory, then avoid the copy to r2 and just return r in that case.
In theory this is a breaking change of behavior if someone is doing e.g.
req2 := req.WithContext(ctx)
and then using both req and req2 though I don't think the behavior is very well defined if you do that.
The text was updated successfully, but these errors were encountered:
Prior to
NewRequestWithContext
a lot of code looked like:Now that
NewRequestWithContext
is a thing, existing code may get ported - incorrectly - as:Under the hood,
WithContext
does this:Basically, my suggestion is to check if the incoming
ctx
and the existingr.ctx
point to the same value in memory, then avoid the copy tor2
and just returnr
in that case.In theory this is a breaking change of behavior if someone is doing e.g.
and then using both
req
andreq2
though I don't think the behavior is very well defined if you do that.The text was updated successfully, but these errors were encountered: