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_test.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_test.go')
| -rw-r--r-- | src/net/http/request_test.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/net/http/request_test.go b/src/net/http/request_test.go index e6748375b5..1608d1c4fe 100644 --- a/src/net/http/request_test.go +++ b/src/net/http/request_test.go @@ -7,6 +7,7 @@ package http_test import ( "bufio" "bytes" + "context" "encoding/base64" "fmt" "io" @@ -785,6 +786,21 @@ func TestMaxBytesReaderStickyError(t *testing.T) { } } +func TestWithContextDeepCopiesURL(t *testing.T) { + req, err := NewRequest("POST", "https://golang.org/", nil) + if err != nil { + t.Fatal(err) + } + + reqCopy := req.WithContext(context.Background()) + reqCopy.URL.Scheme = "http" + + firstURL, secondURL := req.URL.String(), reqCopy.URL.String() + if firstURL == secondURL { + t.Errorf("unexpected change to original request's URL") + } +} + // verify that NewRequest sets Request.GetBody and that it works func TestNewRequestGetBody(t *testing.T) { tests := []struct { |
