Skip to content

Commit 293ed71

Browse files
author
lc
committed
fix(gau): fix urlscan
1 parent 62befc9 commit 293ed71

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

pkg/httpclient/client.go

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,47 +17,51 @@ type Header struct {
1717

1818
func MakeRequest(c *fasthttp.Client, url string, maxRetries uint, timeout uint, headers ...Header) ([]byte, error) {
1919
var (
20-
req *fasthttp.Request
21-
resp *fasthttp.Response
20+
req *fasthttp.Request
21+
respBody []byte
22+
err error
2223
)
2324
retries := int(maxRetries)
2425
for i := retries; i >= 0; i-- {
2526
req = fasthttp.AcquireRequest()
26-
defer fasthttp.ReleaseRequest(req)
2727

2828
req.Header.SetMethod(fasthttp.MethodGet)
2929
for _, header := range headers {
30-
req.Header.Set(header.Key, header.Value)
30+
if header.Key != "" {
31+
req.Header.Set(header.Key, header.Value)
32+
}
3133
}
3234
req.Header.Set(fasthttp.HeaderUserAgent, getUserAgent())
35+
req.Header.Set("Accept", "*/*")
3336
req.SetRequestURI(url)
34-
35-
resp = fasthttp.AcquireResponse()
36-
defer fasthttp.ReleaseResponse(resp)
37-
38-
if err := c.DoTimeout(req, resp, time.Second*time.Duration(timeout)); err != nil {
39-
fasthttp.ReleaseRequest(req)
40-
if retries == 0 {
41-
return nil, err
42-
}
43-
}
44-
45-
if resp.Body() == nil {
46-
if retries == 0 {
47-
return nil, ErrNilResponse
48-
}
49-
}
50-
// url responded with 503, so try again
51-
if resp.StatusCode() == 503 {
52-
continue
37+
respBody, err = doReq(c, req, timeout)
38+
if err == nil {
39+
goto done
5340
}
54-
55-
goto done
5641
}
5742
done:
43+
if err != nil {
44+
return nil, err
45+
}
46+
return respBody, nil
47+
}
48+
49+
// doReq handles http requests
50+
func doReq(c *fasthttp.Client, req *fasthttp.Request, timeout uint) ([]byte, error) {
51+
resp := fasthttp.AcquireResponse()
52+
defer fasthttp.ReleaseResponse(resp)
53+
defer fasthttp.ReleaseRequest(req)
54+
if err := c.DoTimeout(req, resp, time.Second*time.Duration(timeout)); err != nil {
55+
return nil, err
56+
}
5857
if resp.StatusCode() != 200 {
5958
return nil, ErrNon200Response
6059
}
60+
61+
if resp.Body() == nil {
62+
return nil, ErrNilResponse
63+
}
64+
6165
return resp.Body(), nil
6266
}
6367

pkg/providers/urlscan/urlscan.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/lc/gau/v2/pkg/httpclient"
99
"github.com/lc/gau/v2/pkg/providers"
1010
"github.com/sirupsen/logrus"
11+
"strings"
1112
)
1213

1314
const (
@@ -55,7 +56,6 @@ paginate:
5556
if err != nil {
5657
return fmt.Errorf("failed to fetch urlscan: %s", err)
5758
}
58-
5959
var result apiResponse
6060
decoder := jsoniter.NewDecoder(bytes.NewReader(resp))
6161
decoder.UseNumber()
@@ -72,7 +72,7 @@ paginate:
7272

7373
total := len(result.Results)
7474
for i, res := range result.Results {
75-
if res.Page.Domain == domain {
75+
if res.Page.Domain == domain || (c.config.IncludeSubdomains && strings.HasSuffix(res.Page.Domain, domain)) {
7676
results <- res.Page.URL
7777
}
7878

0 commit comments

Comments
 (0)