Skip to content

Commit

Permalink
Add -disableRedirects flag to disable following of redirects (rakyll#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-adams authored and Jaana B. Dogan committed May 31, 2017
1 parent fb2cc10 commit 12b2d74
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hey.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -214,6 +216,7 @@ func main() {
Timeout: *t,
DisableCompression: *disableCompression,
DisableKeepAlives: *disableKeepAlives,
DisableRedirects: *disableRedirects,
H2: *h2,
ProxyAddr: proxyURL,
Output: *output,
Expand Down
9 changes: 9 additions & 0 deletions requester/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 12b2d74

Please sign in to comment.