diff --git a/README.md b/README.md index e31fcc9..af13efe 100644 --- a/README.md +++ b/README.md @@ -22,22 +22,28 @@ Give the target URL and press Enter, then the attack will be launched with defau ### Options #### Rate Limit - The request rate per time unit to issue against the targets. Give 0 then it will send requests as fast as possible. +Default is `50`. #### Duration The amount of time to issue requests to the targets. Give `0s` for an infinite attack. Press `Ctrl-C` to stop. -Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". Default is `10s`. +Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". +Default is `10s`. #### Timeout The timeout for each request. `0s` means to disable timeouts. +Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". +Default is `30s` -**Method** +#### Method +An HTTP request method for each request. -**Header** +#### Header +A request header to be sent. -**Body** +#### Body +The file whose content will be set as the http request body. ## Features diff --git a/attacker/attacker.go b/attacker/attacker.go index ee4c36c..248de0b 100644 --- a/attacker/attacker.go +++ b/attacker/attacker.go @@ -2,6 +2,7 @@ package attacker import ( "context" + "io/ioutil" "net/http" "time" @@ -26,7 +27,7 @@ type Options struct { Duration time.Duration Timeout time.Duration Method string - Body []byte + BodyFile string Header http.Header Attacker Attacker @@ -52,12 +53,21 @@ func Attack(ctx context.Context, target string, resCh chan *Result, opts Options if opts.Attacker == nil { opts.Attacker = vegeta.NewAttacker(vegeta.Timeout(opts.Timeout)) } + var body []byte + if opts.BodyFile != "" { + if b, err := ioutil.ReadFile(opts.BodyFile); err != nil { + // TODO: Report to report widget + return nil + } else { + body = b + } + } rate := vegeta.Rate{Freq: opts.Rate, Per: time.Second} targeter := vegeta.NewStaticTargeter(vegeta.Target{ Method: opts.Method, URL: target, - Body: opts.Body, + Body: body, Header: opts.Header, }) diff --git a/attacker/metrics.go b/attacker/metrics.go index a040786..6496792 100644 --- a/attacker/metrics.go +++ b/attacker/metrics.go @@ -8,7 +8,6 @@ import ( ) // Metrics wraps "vegeta.Metrics" to avoid dependency on it. -// TODO: Add more fields type Metrics struct { // Latencies holds computed request latency metrics. Latencies vegeta.LatencyMetrics `json:"latencies"` diff --git a/gui/keybinds.go b/gui/keybinds.go index b8f79bb..5e0505a 100644 --- a/gui/keybinds.go +++ b/gui/keybinds.go @@ -59,7 +59,6 @@ func makeOptions(w *widgets) (attacker.Options, error) { duration time.Duration timeout time.Duration method string - body string header = make(http.Header) err error ) @@ -97,8 +96,6 @@ func makeOptions(w *widgets) (attacker.Options, error) { } } - body = w.bodyInput.Read() - if s := w.headerInput.Read(); s != "" { parts := strings.SplitN(s, ":", 2) if len(parts) != 2 { @@ -119,7 +116,7 @@ func makeOptions(w *widgets) (attacker.Options, error) { Duration: duration, Timeout: timeout, Method: method, - Body: []byte(body), + BodyFile: w.bodyInput.Read(), Header: header, }, nil }