diff options
| author | Emmanuel Odeke <emm.odeke@gmail.com> | 2017-04-21 11:49:19 -0600 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2017-05-24 04:34:52 +0000 |
| commit | 3b69c3bbed7f49eb2f69729c8edbe8fe2b6cc40a (patch) | |
| tree | 8c6cd481469ffa98cdb67dff08e910dae9c3abee /src/net/http/request.go | |
| parent | 88a235042df2d8344bb4f49a8bfc1642b2cbf37b (diff) | |
| download | go-3b69c3bbed7f49eb2f69729c8edbe8fe2b6cc40a.tar.xz | |
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 <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/http/request.go')
| -rw-r--r-- | src/net/http/request.go | 8 |
1 files changed, 8 insertions, 0 deletions
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 } |
