mirror of
https://github.com/rakyll/hey.git
synced 2026-10-02 07:44:41 +08:00
Use the standard library request cloner
This commit is contained in:
@@ -264,16 +264,8 @@ func (b *Work) runWorkers() {
|
||||
}
|
||||
|
||||
// cloneRequest returns a clone of the provided *http.Request.
|
||||
// The clone is a shallow copy of the struct and its Header map.
|
||||
func cloneRequest(r *http.Request, body []byte) *http.Request {
|
||||
// shallow copy of the struct
|
||||
r2 := new(http.Request)
|
||||
*r2 = *r
|
||||
// deep copy of the Header
|
||||
r2.Header = make(http.Header, len(r.Header))
|
||||
for k, s := range r.Header {
|
||||
r2.Header[k] = append([]string(nil), s...)
|
||||
}
|
||||
r2 := r.Clone(r.Context())
|
||||
if len(body) > 0 {
|
||||
r2.Body = io.NopCloser(bytes.NewReader(body))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user