Skip to content

Commit

Permalink
Merge pull request #25 from brenol/support-multiple-headers
Browse files Browse the repository at this point in the history
support multiple headers
  • Loading branch information
nakabonne committed Oct 1, 2020
2 parents 6d51dac + 895f7e1 commit c08cf45
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ali -h
| `--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". | 10s |
| `--timeout` | The timeout for each request. `0s` means to disable timeouts. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". | 30s |
| `--method` | An HTTP request method for each request. | GET |
| `--header` | A request header to be sent. | |
| `--header` | A request header to be sent. Can be used multiple times to send multiple headers | |
| `--body` | A request body to be sent. | |
| `--body-file` | The path to file whose content will be set as the http request body. | |

Expand Down
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type cli struct {
duration time.Duration
timeout time.Duration
method string
header string
headers []string
body string
bodyFile string

Expand All @@ -68,7 +68,7 @@ func main() {
flagSet.DurationVarP(&c.duration, "duration", "d", time.Second*10, "the amount of time to issue requests to the targets")
flagSet.DurationVarP(&c.timeout, "timeout", "t", time.Second*30, "the timeout for each request")
flagSet.StringVarP(&c.method, "method", "m", "GET", "an HTTP request method for each request")
flagSet.StringVarP(&c.header, "header", "H", "", "a request header to be sent")
flagSet.StringSliceVarP(&c.headers, "header", "H", []string{}, "a request header to be sent. can be used multiple times to send multiple headers")
flagSet.StringVarP(&c.body, "body", "b", "", "a request body to be sent")
flagSet.StringVarP(&c.bodyFile, "body-file", "B", "", "the file whose content will be set as the http request body")
flagSet.BoolVarP(&c.version, "version", "v", false, "print the current version")
Expand Down Expand Up @@ -123,14 +123,14 @@ func (c *cli) makeOptions() (*attacker.Options, error) {
}

header := make(http.Header)
if c.header != "" {
parts := strings.SplitN(c.header, ":", 2)
for _, hdr := range c.headers {
parts := strings.SplitN(hdr, ":", 2)
if len(parts) != 2 {
return nil, fmt.Errorf("given header %q has a wrong format", c.header)
return nil, fmt.Errorf("given header %q has a wrong format", hdr)
}
key, val := strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])
if key == "" || val == "" {
return nil, fmt.Errorf("given header %q has a wrong format", c.header)
return nil, fmt.Errorf("given header %q has a wrong format", hdr)
}
// NOTE: Add key/value directly to the http.Header (map[string][]string).
// http.Header.Add() canonicalizes keys but the vegeta API is used to test systems that require case-sensitive headers.
Expand Down

0 comments on commit c08cf45

Please sign in to comment.