Skip to content

Commit

Permalink
fix(gau): fix http client retries
Browse files Browse the repository at this point in the history
  • Loading branch information
lc committed Nov 15, 2021
1 parent 35af1c6 commit cb0a0b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
6 changes: 2 additions & 4 deletions cmd/gau/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 7 additions & 9 deletions pkg/httpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit cb0a0b8

Please sign in to comment.