Skip to content

armgit / hey

Public Imported from GitHub
0

HTTP load generator, ApacheBench (ab) replacement

Go

Add -disableRedirects flag to disable following of redirects (#41)

Mark Adams12b2d74b9fe3
diff --git a/hey.go b/hey.go
index 7001d3c..71b59c7 100644
--- a/hey.go
+++ b/hey.go
@@ -69,6 +69,7 @@ var (
disableCompression = flag.Bool("disable-compression", false, "")
disableKeepAlives = flag.Bool("disable-keepalive", false, "")
+ disableRedirects = flag.Bool("disable-redirects", false, "")
proxyAddr = flag.String("x", "", "")
enableTrace = flag.Bool("more", false, "")
@@ -102,6 +103,7 @@ Options:
-disable-compression Disable compression.
-disable-keepalive Disable keep-alive, prevents re-use of TCP
connections between different HTTP requests.
+ -disable-redirects Disable following of HTTP redirects
-cpus Number of used cpu cores.
(default for current machine is %d cores)
-more Provides information on DNS lookup, dialup, request and
@@ -214,6 +216,7 @@ func main() {
Timeout: *t,
DisableCompression: *disableCompression,
DisableKeepAlives: *disableKeepAlives,
+ DisableRedirects: *disableRedirects,
H2: *h2,
ProxyAddr: proxyURL,
Output: *output,
diff --git a/requester/requester.go b/requester/requester.go
index 6f05cdd..ec6eb5d 100644
--- a/requester/requester.go
+++ b/requester/requester.go
@@ -76,6 +76,9 @@ type Work struct {
// DisableKeepAlives is an option to prevents re-use of TCP connections between different HTTP requests
DisableKeepAlives bool
+ // DisableRedirects is an option to prevent the following of HTTP redirects
+ DisableRedirects bool
+
// Output represents the output type. If "csv" is provided, the
// output will be dumped as a csv stream.
Output string
@@ -232,7 +235,13 @@ func (b *Work) runWorker(n int) {
} else {
tr.TLSNextProto = make(map[string]func(string, *tls.Conn) http.RoundTripper)
}
+
client := &http.Client{Transport: tr, Timeout: time.Duration(b.Timeout) * time.Second}
+ if b.DisableRedirects {
+ client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
+ return http.ErrUseLastResponse
+ }
+ }
for i := 0; i < n; i++ {
if b.QPS > 0 {
<-throttle