Skip to content

Commit

Permalink
Add comments support to HTTP targets format (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-oliva authored and tsenart committed Jan 4, 2019
1 parent 0cabfc9 commit 7b55bde
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ X-Account-ID: 99
@/path/to/newthing.json
```

###### Add comments to the targets
Lines starting with # are ignored.

```
# get a dragon ball
GET http://goku:9090/path/to/dragon?item=ball
```

#### `-h2c`

Specifies that HTTP2 requests are to be sent over TCP without TLS encryption.
Expand Down
3 changes: 2 additions & 1 deletion lib/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ func NewHTTPTargeter(src io.Reader, body []byte, hdr http.Header) Targeter {
return ErrNoTargets
}
line = strings.TrimSpace(sc.Text())
if len(line) != 0 {

if len(line) != 0 && line[0] != '#'{
break
}
}
Expand Down
16 changes: 15 additions & 1 deletion lib/targets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,12 @@ func TestNewHTTPTargeter(t *testing.T) {
@`, bodyf.Name(),
`
SUBSCRIBE http://foobar.org/sub`,
SUBSCRIBE http://foobar.org/sub
# GET TEST
GET http://:6060/
X-Header: 1
X-Header: 2`,
)

src := bytes.NewBufferString(strings.TrimSpace(targets))
Expand Down Expand Up @@ -360,6 +365,15 @@ func TestNewHTTPTargeter(t *testing.T) {
Body: []byte{},
Header: http.Header{"Content-Type": []string{"text/plain"}},
},
{
Method: "GET",
URL: "http://:6060/",
Body: []byte{},
Header: http.Header{
"X-Header": []string{"1", "2"},
"Content-Type": []string{"text/plain"},
},
},
} {
var got Target
if err := read(&got); err != nil {
Expand Down

0 comments on commit 7b55bde

Please sign in to comment.