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

This commit is contained in:
Mark Adams
2017-05-31 12:33:00 -05:00
committed by Jaana B. Dogan
parent fb2cc10326
commit 12b2d74b9f
2 changed files with 12 additions and 0 deletions

3
hey.go
View File

@@ -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,

View File

@@ -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