Skip to content

Commit 04f96be

Browse files
authored
Merge pull request #81 from lc/lc/fix-urlscan
fix(gau): fix urlscan provider
2 parents 62befc9 + 448956b commit 04f96be

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

pkg/httpclient/client.go

+29-25
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/providers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"github.com/valyala/fasthttp"
66
)
77

8-
const Version = `2.1.1`
8+
const Version = `2.1.2`
99

1010
// Provider is a generic interface for all archive fetchers
1111
type Provider interface {

pkg/providers/urlscan/urlscan.go

+2-2
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)