Skip to content

armgit / hey

Public Imported from GitHub
0

HTTP load generator, ApacheBench (ab) replacement

Go

Added support for TCP/HTTP proxy

Ox To A Carte47d49c8cf6a
diff --git a/boom.go b/boom.go
index 8810d56..0bb5dde 100644
--- a/boom.go
+++ b/boom.go
@@ -24,17 +24,18 @@ import (
"regexp"
"strings"
- "github.com/rakyll/boom/commands"
+ "github.com/oxtoacart/boom/commands"
)
var (
- flagMethod = flag.String("m", "GET", "")
- flagHeaders = flag.String("h", "", "")
- flagD = flag.String("d", "", "")
- flagType = flag.String("T", "text/html", "")
- flagAuth = flag.String("a", "", "")
- flagInsecure = flag.Bool("allow-insecure", false, "")
- flagOutput = flag.String("o", "", "")
+ flagMethod = flag.String("m", "GET", "")
+ flagHeaders = flag.String("h", "", "")
+ flagD = flag.String("d", "", "")
+ flagType = flag.String("T", "text/html", "")
+ flagAuth = flag.String("a", "", "")
+ flagInsecure = flag.Bool("allow-insecure", false, "")
+ flagOutput = flag.String("o", "", "")
+ flagProxyAddr = flag.String("x", "", "")
flagC = flag.Int("c", 50, "")
flagN = flag.Int("n", 200, "")
@@ -58,6 +59,7 @@ Options:
-d HTTP request body.
-T Content-type, defaults to "text/html".
-a Basic authentication, username:password.
+ -x TCP/HTTP Proxy address as host:port
-allow-insecure Allow bad/expired TLS/SSL certificates.
`
@@ -154,7 +156,8 @@ func main() {
Qps: q,
Timeout: t,
AllowInsecure: *flagInsecure,
- Output: *flagOutput}).Run()
+ Output: *flagOutput,
+ ProxyAddr: *flagProxyAddr}).Run()
}
// Replaces host with an IP and returns the provided
diff --git a/commands/boom.go b/commands/boom.go
index 7d2c4ea..037f6c6 100644
--- a/commands/boom.go
+++ b/commands/boom.go
@@ -73,6 +73,9 @@ type Boom struct {
// Output type
Output string
+ // Optional address of HTTP proxy server as host:port
+ ProxyAddr string
+
bar *pb.ProgressBar
rpt *report
results chan *result
diff --git a/commands/run.go b/commands/run.go
index 9ae26b3..ea06813 100644
--- a/commands/run.go
+++ b/commands/run.go
@@ -16,6 +16,7 @@ package commands
import (
"crypto/tls"
+ "io/ioutil"
"net"
"net/http"
"sync"
@@ -36,6 +37,11 @@ func (b *Boom) worker(ch chan *http.Request) {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: b.AllowInsecure, ServerName: host},
}
+ if b.ProxyAddr != "" {
+ tr.Dial = func(network string, addr string) (conn net.Conn, err error) {
+ return net.Dial(network, b.ProxyAddr)
+ }
+ }
client := &http.Client{Transport: tr}
for req := range ch {
s := time.Now()
@@ -47,6 +53,8 @@ func (b *Boom) worker(ch chan *http.Request) {
if resp.ContentLength > 0 {
size = resp.ContentLength
}
+ // consume the whole body
+ ioutil.ReadAll(resp.Body)
// cleanup body, so the socket can be reusable
resp.Body.Close()
}