Skip to content

Commit

Permalink
net/http: fix Request.Clone with SetPathValue
Browse files Browse the repository at this point in the history
Fixes #64911
  • Loading branch information
callthingsoff committed Jan 1, 2024
1 parent b25f555 commit 1ca0941
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/net/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,20 @@ func (r *Request) Clone(ctx context.Context) *Request {
r2.Form = cloneURLValues(r.Form)
r2.PostForm = cloneURLValues(r.PostForm)
r2.MultipartForm = cloneMultipartForm(r.MultipartForm)

// See issue 64911.
if s := r.matches; s != nil {
s2 := make([]string, len(s))
copy(s2, s)
r2.matches = s2
}
if s := r2.otherValues; s != nil {
s2 := make(map[string]string, len(s))
for k, v := range s {
s2[k] = v
}
r2.otherValues = s2
}
return r2
}

Expand Down
15 changes: 15 additions & 0 deletions src/net/http/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,21 @@ func TestRequestCloneTransferEncoding(t *testing.T) {
}
}

func TestRequestClonePathValues(t *testing.T) {
orig, err := http.NewRequest("GET", "https://example.com/", nil)
if err != nil {
panic(err)
}
orig.SetPathValue("orig", "orig")

copy := orig.Clone(context.Background())
copy.SetPathValue("copy", "copy")

if orig.PathValue("copy") != "" {
t.Fatal("orig.PathValue is changed")
}
}

// Issue 34878: verify we don't panic when including basic auth (Go 1.13 regression)
func TestNoPanicOnRoundTripWithBasicAuth(t *testing.T) { run(t, testNoPanicWithBasicAuth) }
func testNoPanicWithBasicAuth(t *testing.T, mode testMode) {
Expand Down

0 comments on commit 1ca0941

Please sign in to comment.