Skip to content

Commit

Permalink
mark responses as success in no redirect following mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
keijiyoshida committed Mar 3, 2017
1 parent 06c3677 commit c88138a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"net"
"net/http"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -94,11 +93,17 @@ func Connections(n int) func(*Attacker) {
func Redirects(n int) func(*Attacker) {
return func(a *Attacker) {
a.redirects = n
a.client.CheckRedirect = func(_ *http.Request, via []*http.Request) error {
if len(via) > n {
return fmt.Errorf("stopped after %d redirects", n)
if n == NoFollow {
a.client.CheckRedirect = func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse
}
} else {
a.client.CheckRedirect = func(_ *http.Request, via []*http.Request) error {
if len(via) > n {
return fmt.Errorf("stopped after %d redirects", n)
}
return nil
}
return nil
}
}
}
Expand Down Expand Up @@ -242,10 +247,11 @@ func (a *Attacker) hit(tr Targeter, tm time.Time) *Result {
r, err := a.client.Do(req)
if err != nil {
// ignore redirect errors when the user set --redirects=NoFollow
if a.redirects == NoFollow && strings.Contains(err.Error(), "stopped after") {
if a.redirects == NoFollow && err == http.ErrUseLastResponse {
err = nil
} else {
return &res
}
return &res
}
defer r.Body.Close()

Expand Down

0 comments on commit c88138a

Please sign in to comment.