aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby Powers <bobbypowers@gmail.com>2022-04-08 12:21:33 -0700
committerDamien Neil <dneil@google.com>2022-04-15 15:57:52 +0000
commit2c73f5f32fceb31b5da7f9a820c0c637f57a9ab5 (patch)
tree8947931a65ba5d33081c9dc6267c8e7ee3f26aaa
parent35a92f92bd0ce15c658dd6794238ca90b71e4422 (diff)
downloadgo-2c73f5f32fceb31b5da7f9a820c0c637f57a9ab5.tar.gz
go-2c73f5f32fceb31b5da7f9a820c0c637f57a9ab5.zip
net/http: remove cloneURL call in WithContext
Fixes #52239 Change-Id: I08b75e613e3c976855e39d01a6757d94e4207bf8 Reviewed-on: https://go-review.googlesource.com/c/go/+/399155 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
-rw-r--r--src/net/http/request.go1
-rw-r--r--src/net/http/request_test.go14
2 files changed, 3 insertions, 12 deletions
diff --git a/src/net/http/request.go b/src/net/http/request.go
index 654505d819..312211977d 100644
--- a/src/net/http/request.go
+++ b/src/net/http/request.go
@@ -359,7 +359,6 @@ func (r *Request) WithContext(ctx context.Context) *Request {
r2 := new(Request)
*r2 = *r
r2.ctx = ctx
- r2.URL = cloneURL(r.URL) // legacy behavior; TODO: try to remove. Issue 23544
return r2
}
diff --git a/src/net/http/request_test.go b/src/net/http/request_test.go
index 4363e11033..d285840c1c 100644
--- a/src/net/http/request_test.go
+++ b/src/net/http/request_test.go
@@ -998,23 +998,15 @@ func TestMaxBytesReaderDifferentLimits(t *testing.T) {
}
}
-func TestWithContextDeepCopiesURL(t *testing.T) {
+func TestWithContextNilURL(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")
- }
-
- // And also check we don't crash on nil (Issue 20601)
+ // Issue 20601
req.URL = nil
- reqCopy = req.WithContext(context.Background())
+ reqCopy := req.WithContext(context.Background())
if reqCopy.URL != nil {
t.Error("expected nil URL in cloned request")
}