Skip to content

armgit / hey

Public Imported from GitHub
0

HTTP load generator, ApacheBench (ab) replacement

Go

Add the missing body to the cloned requests.

Burcu Dogan9078dc98e5f4
diff --git a/boom.go b/boom.go
index 423d7f6..6601f76 100644
--- a/boom.go
+++ b/boom.go
@@ -154,17 +154,18 @@ func main() {
}
}
- req, err := http.NewRequest(method, url, strings.NewReader(*body))
+ req, err := http.NewRequest(method, url, nil)
if err != nil {
usageAndExit(err.Error())
}
req.Header = header
- if username != "" && password != "" {
+ if username != "" || password != "" {
req.SetBasicAuth(username, password)
}
(&boomer.Boomer{
Request: req,
+ RequestBody: *body,
N: num,
C: conc,
Qps: q,
diff --git a/boomer/boomer.go b/boomer/boomer.go
index 90ed794..5ca4eb6 100644
--- a/boomer/boomer.go
+++ b/boomer/boomer.go
@@ -21,6 +21,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
+ "strings"
"sync"
"time"
@@ -42,6 +43,8 @@ type Boomer struct {
// Request is the request to be made.
Request *http.Request
+ RequestBody string
+
// N is the total number of requests to make.
N int
@@ -174,7 +177,7 @@ func (b *Boomer) runWorkers() {
if b.Qps > 0 {
<-throttle
}
- jobsch <- cloneRequest(b.Request)
+ jobsch <- cloneRequest(b.Request, b.RequestBody)
}
close(jobsch)
@@ -183,7 +186,7 @@ func (b *Boomer) 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) *http.Request {
+func cloneRequest(r *http.Request, body string) *http.Request {
// shallow copy of the struct
r2 := new(http.Request)
*r2 = *r
@@ -192,5 +195,6 @@ func cloneRequest(r *http.Request) *http.Request {
for k, s := range r.Header {
r2.Header[k] = append([]string(nil), s...)
}
+ r2.Body = ioutil.NopCloser(strings.NewReader(body))
return r2
}