diff --git a/args.go b/args.go index 5fed13f..677414d 100644 --- a/args.go +++ b/args.go @@ -25,6 +25,7 @@ type config struct { followLocation bool method string saveStatus int + timeout int verbose bool paths string @@ -66,6 +67,11 @@ func processArgs() config { flag.IntVar(&saveStatus, "savestatus", 0, "") flag.IntVar(&saveStatus, "s", 0, "") + // timeout param + timeout := 10000 + flag.IntVar(&timeout, "timeout", 10000, "") + flag.IntVar(&timeout, "t", 10000, "") + // rawhttp param rawHTTP := false flag.BoolVar(&rawHTTP, "rawhttp", false, "") @@ -109,6 +115,7 @@ func processArgs() config { followLocation: followLocation, method: method, saveStatus: saveStatus, + timeout: timeout, requester: requesterFn, verbose: verbose, paths: paths, @@ -126,11 +133,12 @@ func init() { h += "Options:\n" h += " -c, --concurrency Set the concurrency level (defaut: 20)\n" - h += " -d, --delay Milliseconds between requests to the same host (defaut: 5000)\n" + h += " -d, --delay Milliseconds between requests to the same host (defaut: 5000)\n" h += " -H, --header
Send a custom HTTP header\n" h += " -L, --location Follow redirects / location header\n" h += " -r, --rawhttp Use the rawhttp library for requests (experimental)\n" h += " -s, --savestatus Save only responses with specific status code\n" + h += " -t, --timeout Set the HTTP timeout (default: 10000)\n" h += " -v, --verbose Verbose mode\n" h += " -X, --method HTTP method (default: GET)\n\n" diff --git a/gohttp.go b/gohttp.go index fb416fd..b10cede 100644 --- a/gohttp.go +++ b/gohttp.go @@ -6,7 +6,6 @@ import ( "io/ioutil" "net/http" "strings" - "time" ) var transport = &http.Transport{ @@ -15,10 +14,10 @@ var transport = &http.Transport{ var httpClient = &http.Client{ Transport: transport, - Timeout: time.Second * 10, } func goRequest(r request) response { + httpClient.Timeout = r.timeout if !r.followLocation { httpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error { diff --git a/main.go b/main.go index 0bba9c9..2722874 100644 --- a/main.go +++ b/main.go @@ -132,6 +132,7 @@ func main() { path: prefixedPath, headers: c.headers, followLocation: c.followLocation, + timeout: time.Duration(c.timeout * 1000000), } } } diff --git a/request.go b/request.go index 34fc74f..ba24083 100644 --- a/request.go +++ b/request.go @@ -3,6 +3,7 @@ package main import ( "net/url" "strings" + "time" ) // a request is a wrapper for a URL that we want to request @@ -13,6 +14,7 @@ type request struct { headers []string followLocation bool + timeout time.Duration } // Hostname returns the hostname part of the request