Skip to content

armgit / hey

Public Imported from GitHub
0

HTTP load generator, ApacheBench (ab) replacement

Go

Introduce the readall flag to allow users to consume the request body entirely.

Burcu Dogan5d051b61ca6c
diff --git a/boom.go b/boom.go
index 4d4576a..a6076bf 100644
--- a/boom.go
+++ b/boom.go
@@ -40,6 +40,7 @@ var (
accept = flag.String("A", "", "")
contentType = flag.String("T", "text/html", "")
authHeader = flag.String("a", "", "")
+ readAll = flag.Bool("readall", false, "")
output = flag.String("o", "", "")
@@ -75,6 +76,7 @@ Options:
-a Basic authentication, username:password.
-x HTTP Proxy address as host:port.
+ -readall Consumes the entire request body.
-allow-insecure Allow bad/expired TLS/SSL certificates.
-disable-compression Disable compression.
-disable-keepalive Disable keep-alive, prevents re-use of TCP
@@ -161,6 +163,7 @@ func main() {
Header: header,
Username: username,
Password: password,
+ ReadAll: *readAll,
},
N: num,
C: conc,
diff --git a/boomer/boomer.go b/boomer/boomer.go
index 65d42e1..20835f3 100644
--- a/boomer/boomer.go
+++ b/boomer/boomer.go
@@ -38,6 +38,7 @@ type ReqOpts struct {
Body string
Username string
Password string
+ ReadAll bool
}
// Creates a req object from req options
diff --git a/boomer/run.go b/boomer/run.go
index 1139655..a6cb1c5 100644
--- a/boomer/run.go
+++ b/boomer/run.go
@@ -16,10 +16,10 @@ package boomer
import (
"crypto/tls"
-
- "sync"
-
+ "io"
+ "io/ioutil"
"net/http"
+ "sync"
"time"
)
@@ -41,7 +41,7 @@ func (b *Boomer) Run() {
close(b.results)
}
-func (b *Boomer) worker(wg *sync.WaitGroup, ch chan *http.Request) {
+func (b *Boomer) worker(wg *sync.WaitGroup, ch chan *http.Request, readAll bool) {
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: b.AllowInsecure,
@@ -52,22 +52,30 @@ func (b *Boomer) worker(wg *sync.WaitGroup, ch chan *http.Request) {
TLSHandshakeTimeout: time.Duration(b.Timeout) * time.Millisecond,
Proxy: http.ProxyURL(b.ProxyAddr),
}
+
client := &http.Client{Transport: tr}
for req := range ch {
s := time.Now()
- code := 0
- size := int64(0)
+
+ var code int
+ var size int64
+
resp, err := client.Do(req)
+
if err == nil {
size = resp.ContentLength
code = resp.StatusCode
+ if readAll {
+ _, err = io.Copy(ioutil.Discard, resp.Body)
+ }
resp.Body.Close()
}
+
if b.bar != nil {
b.bar.Increment()
}
- wg.Done()
+ wg.Done()
b.results <- &result{
statusCode: code,
duration: time.Now().Sub(s),
@@ -88,7 +96,7 @@ func (b *Boomer) run() {
jobs := make(chan *http.Request, b.N)
for i := 0; i < b.C; i++ {
go func() {
- b.worker(&wg, jobs)
+ b.worker(&wg, jobs, b.Req.ReadAll)
}()
}
for i := 0; i < b.N; i++ {