Skip to content

Commit

Permalink
Try to support multiple custom headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
gyakkun authored and rogerwelin committed Sep 9, 2024
1 parent 4c2c832 commit a83f96e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
15 changes: 9 additions & 6 deletions cmd/cassowary/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,14 @@ func validateCLI(c *cli.Context) error {
prometheusEnabled = true
}

if c.String("header") != "" {
length := 0
length, header = client.SplitHeader(c.String("header"))
if length != 2 {
return errNotValidHeader
if len(c.StringSlice("header")) != 0 {
allHeaders := c.StringSlice("header")
for _, hdr := range allHeaders {
thisLen, thisHdr := client.SplitHeader(hdr)
if thisLen != 2 {
return errNotValidHeader
}
header = append(header, thisHdr...)
}
}

Expand Down Expand Up @@ -279,7 +282,7 @@ func runCLI(args []string) {
Aliases: []string{"prompushgwurl"},
Usage: "specify prometheus push gateway url to send metrics (optional)",
},
&cli.StringFlag{
&cli.StringSliceFlag{
Name: "H",
Aliases: []string{"header"},
Usage: "add arbitrary header, eg. 'Host: www.example.com'",
Expand Down
9 changes: 7 additions & 2 deletions pkg/client/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ func (c *Cassowary) runLoadTest(outPutChan chan<- durationMetrics, workerChan ch
}
}

if len(c.RequestHeader) == 2 {
request.Header.Add(c.RequestHeader[0], c.RequestHeader[1])
if len(c.RequestHeader)%2 == 0 {
for idx := range c.RequestHeader {
if idx%2 == 1 {
continue
}
request.Header.Add(c.RequestHeader[idx], c.RequestHeader[idx+1])
}
}

var t0, t1, t2, t3, t4, t5, t6 time.Time
Expand Down

0 comments on commit a83f96e

Please sign in to comment.