From 3b69c3bbed7f49eb2f69729c8edbe8fe2b6cc40a Mon Sep 17 00:00:00 2001 From: Emmanuel Odeke Date: Fri, 21 Apr 2017 11:49:19 -0600 Subject: net/http: deep copy Request.URL also in Request.WithContext's copy Despite the previously known behavior of Request.WithContext shallow copying a request, usage of the request inside server.ServeHTTP mutates the request's URL. This CL implements deep copying of the URL. Fixes #20068 Change-Id: I86857d7259e23ac624d196401bf12dde401c42af Reviewed-on: https://go-review.googlesource.com/41308 Run-TryBot: Emmanuel Odeke TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/net/http/request.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/net/http/request.go') diff --git a/src/net/http/request.go b/src/net/http/request.go index 739970b28c..82466d9b36 100644 --- a/src/net/http/request.go +++ b/src/net/http/request.go @@ -329,6 +329,14 @@ func (r *Request) WithContext(ctx context.Context) *Request { r2 := new(Request) *r2 = *r r2.ctx = ctx + + // Deep copy the URL because it isn't + // a map and the URL is mutable by users + // of WithContext. + r2URL := new(url.URL) + *r2URL = *r.URL + r2.URL = r2URL + return r2 } -- cgit v1.3-5-g9baa