Skip to content

Commit 8b08f1a

Browse files
committed
add request timeout
1 parent d6c5ae5 commit 8b08f1a

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ var reportPath string
2121

2222
func main() {
2323
var requestURL, method, postData, contentType, wordlist string
24-
var chunkSize int
24+
var chunkSize, timeout int
2525
flag.StringVar(&requestURL, "url", "", "The URL to make the request to")
2626
flag.StringVar(&method, "method", "GET", "HTTP method to use")
2727
flag.StringVar(&postData, "data", "", "Optional POST data")
2828
flag.StringVar(&contentType, "type", "form", "Content type: form, json, xml")
2929
flag.StringVar(&wordlist, "wordlist", "wordlist.txt", "Path to the wordlist file")
3030
flag.StringVar(&reportPath, "report", "report.json", "Path to the output report file")
3131
flag.IntVar(&chunkSize, "chunk-size", 1000, "Number of parameters to send in each request")
32+
flag.IntVar(&timeout, "timeout", 10, "Request timeout in seconds")
3233
flag.BoolVar(&ignoreCertErrors, "ignore-cert", false, "Ignore SSL certificate errors")
3334

3435
flag.Parse()
@@ -45,6 +46,7 @@ func main() {
4546
Method: method,
4647
Data: postData,
4748
ContentType: contentType,
49+
Timeout: timeout,
4850
}
4951
results := DiscoverParams(request, params, chunkSize)
5052
logger.Info("Total requests made", "count", totalRequests)
@@ -61,6 +63,7 @@ type Request struct {
6163
Method string `json:"method"`
6264
Data string `json:"data"`
6365
ContentType string `json:"content_type"`
66+
Timeout int `json:"timeout"`
6467
}
6568

6669
type Results struct {
@@ -244,7 +247,7 @@ func makeRequest(request Request, params url.Values) ResponseData {
244247
logger.Error("Failed to create request", "error", err)
245248
}
246249

247-
client := createHTTPClient()
250+
client := createHTTPClient(request.Timeout)
248251
resp, err := client.Do(req)
249252
if err != nil {
250253
logger.Error("Failed to make request", "error", err)

utils.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"net/url"
1010
"os"
11+
"time"
1112

1213
"github.com/PuerkitoBio/goquery"
1314
)
@@ -69,12 +70,12 @@ func countReflections(params url.Values, body []byte) int {
6970
return count
7071
}
7172

72-
func createHTTPClient() *http.Client {
73+
func createHTTPClient(timeout int) *http.Client {
7374
if ignoreCertErrors {
7475
tr := &http.Transport{
7576
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
7677
}
77-
return &http.Client{Transport: tr}
78+
return &http.Client{Transport: tr, Timeout: time.Duration(timeout) * time.Second}
7879
}
7980
return &http.Client{}
8081
}

0 commit comments

Comments
 (0)