Skip to content

Commit 1e3d56a

Browse files
authored
Merge pull request #448 from hdm/bug/url-clone-race
Fix data race caused by concurrent access to the request URL during scans
2 parents 5f6e8d1 + 7b909a9 commit 1e3d56a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

request.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,25 @@ func (r *Request) BodyBytes() ([]byte, error) {
105105

106106
// Update request URL with new changes of parameters if any
107107
func (r *Request) Update() {
108+
// Make a copy of the URL to avoid data races
109+
r.URL = r.URL.Clone()
108110
r.URL.Update()
111+
r.Request.URL = r.URL.URL
109112
updateScheme(r.URL.URL)
110113
}
111114

112115
// SetURL updates request url (i.e http.Request.URL) with given url
113116
func (r *Request) SetURL(u *urlutil.URL) {
114-
r.URL = u
117+
// Make a copy of the URL to avoid data races
118+
r.URL = u.Clone()
115119
r.Request.URL = u.URL
116120
r.Update()
117121
}
118122

119123
// Clones and returns new Request
120124
func (r *Request) Clone(ctx context.Context) *Request {
121125
r.Update()
122-
ux := r.URL.Clone()
126+
ux := r.URL
123127
req := r.Request.Clone(ctx)
124128
req.URL = ux.URL
125129
ux.Update()

0 commit comments

Comments
 (0)