]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: remove cloneURL call in WithContext
authorBobby Powers <bobbypowers@gmail.com>
Fri, 8 Apr 2022 19:21:33 +0000 (12:21 -0700)
committerDamien Neil <dneil@google.com>
Fri, 15 Apr 2022 15:57:52 +0000 (15:57 +0000)
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>
src/net/http/request.go
src/net/http/request_test.go

index 654505d81915b595fe464802bd3a504d1629595a..312211977d55429dc5db6d69c0082e279c3eb8e6 100644 (file)
@@ -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
 }
 
index 4363e1103332567d28e7d0a4103945241cda87a1..d285840c1cec424e80a1ba45989d1c006605d75d 100644 (file)
@@ -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")
        }