Skip to content
This repository has been archived by the owner on Mar 12, 2022. It is now read-only.

Commit

Permalink
add timeout flag
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkvist committed Jul 12, 2019
1 parent 8a98ea1 commit 6d297fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ Usage:
whisperer [flags]
Flags:
-a, --agent string user agent (default "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0")
-d, --delay duration delay between requests
-g, --goroutines int number of goroutines (default 1)
-h, --help help for whisperer
--urls string simple .txt file with URL's to visit (default "./urls.txt")
-v, --verbose enables verbose mode
-a, --agent string user agent (default "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0")
-d, --delay duration delay between requests (default 1s)
-g, --goroutines int number of goroutines (default 1)
-h, --help help for whisperer
-t, --timeout duration max time to wait for a response before canceling the request (default 3s)
--urls string simple .txt file with URL's to visit (default "./urls.txt")
-v, --verbose enables verbose mode
```

## URLs file
Expand Down
6 changes: 4 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ var (
agent string
delay time.Duration
goroutines int
timeout time.Duration
urls string
verbose bool
)

func init() {
rootCmd.PersistentFlags().StringVarP(&agent, "agent", "a", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0", "user agent")
rootCmd.PersistentFlags().DurationVarP(&delay, "delay", "d", 0, "delay between requests")
rootCmd.PersistentFlags().DurationVarP(&delay, "delay", "d", 1*time.Second, "delay between requests")
rootCmd.PersistentFlags().IntVarP(&goroutines, "goroutines", "g", 1, "number of goroutines")
rootCmd.PersistentFlags().DurationVarP(&timeout, "timeout", "t", 3*time.Second, "max time to wait for a response before canceling the request")
rootCmd.PersistentFlags().StringVar(&urls, "urls", "./urls.txt", "simple .txt file with URL's to visit")
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "enables verbose mode")
}
Expand All @@ -45,7 +47,7 @@ var rootCmd = &cobra.Command{
return fmt.Errorf("while reading URLs from %q: %v", urls, err)
}

client := &http.Client{}
client := &http.Client{Timeout: timeout}
sema := make(chan struct{}, goroutines)
seed := rand.NewSource(time.Now().Unix())
r := rand.New(seed)
Expand Down

0 comments on commit 6d297fc

Please sign in to comment.