HTTP load generator, ApacheBench (ab) replacement
Go
body should be a byte slice
Jaana Burcu Dogan9cf60f73cbad
diff --git a/hey.go b/hey.goindex 9dec211..6e3890d 100644--- a/hey.go+++ b/hey.go@@ -191,7 +191,7 @@ func main() {(&requester.Work{Request: req,- RequestBody: *body,+ RequestBody: []byte(*body),N: num,C: conc,QPS: q,diff --git a/requester/requester.go b/requester/requester.goindex 6e0d4e1..e6063d4 100644--- a/requester/requester.go+++ b/requester/requester.go@@ -16,6 +16,7 @@package requesterimport (+ "bytes""crypto/tls""io""io/ioutil"@@ -24,7 +25,6 @@ import ("net/url""os""os/signal"- "strings""sync""time"@@ -47,7 +47,7 @@ type Work struct {// Request is the request to be made.Request *http.Request- RequestBody string+ RequestBody []byte// N is the total number of requests to make.N int@@ -206,7 +206,7 @@ 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 string) *http.Request {+func cloneRequest(r *http.Request, body []byte) *http.Request {// shallow copy of the structr2 := new(http.Request)*r2 = *r@@ -215,6 +215,6 @@ func cloneRequest(r *http.Request, body string) *http.Request {for k, s := range r.Header {r2.Header[k] = append([]string(nil), s...)}- r2.Body = ioutil.NopCloser(strings.NewReader(body))+ r2.Body = ioutil.NopCloser(bytes.NewReader(body))return r2}