From cb0a0b81bf796d9e50d1831ab819973c8d68b6be Mon Sep 17 00:00:00 2001 From: lc Date: Sun, 14 Nov 2021 19:48:23 -0600 Subject: [PATCH] fix(gau): fix http client retries --- cmd/gau/main.go | 6 ++---- pkg/httpclient/client.go | 16 +++++++--------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/cmd/gau/main.go b/cmd/gau/main.go index 35ab15f..6449076 100644 --- a/cmd/gau/main.go +++ b/cmd/gau/main.go @@ -67,19 +67,17 @@ func main() { }() } - domains := make(chan string) gau.Start(domains, results) - if len(flags.Args()) > 0 { for _, domain := range flags.Args() { - domains <-domain + domains <- domain } } else { sc := bufio.NewScanner(os.Stdin) for sc.Scan() { - domains <-sc.Text() + domains <- sc.Text() } if err := sc.Err(); err != nil { diff --git a/pkg/httpclient/client.go b/pkg/httpclient/client.go index a094294..b1c9186 100644 --- a/pkg/httpclient/client.go +++ b/pkg/httpclient/client.go @@ -2,13 +2,12 @@ package httpclient import ( "errors" - "fmt" "github.com/valyala/fasthttp" "math/rand" "time" ) -var ErrNilResponse = errors.New("empty response, check your proxy configuration") +var ErrNilResponse = errors.New("unexpected nil response") var ErrNon200Response = errors.New("API responded with non-200 status code") type Header struct { @@ -39,16 +38,15 @@ func MakeRequest(c *fasthttp.Client, url string, maxRetries int, headers ...Head if err := c.DoTimeout(req, resp, time.Second*45); err != nil { fasthttp.ReleaseRequest(req) if retries == 0 { - break + return nil, err } } - } - if retries == 0 { - return nil, fmt.Errorf("httpclient: out of retries") - } - if resp.Body() == nil { - return nil, ErrNilResponse + if resp.Body() == nil { + if retries == 0 { + return nil, ErrNilResponse + } + } } if resp.StatusCode() != 200 {