Skip to content

Commit

Permalink
Fix comments between headers (#447) (#448)
Browse files Browse the repository at this point in the history
Add the possibility to add comment between headers

Fixes #447
  • Loading branch information
mbodock authored and tsenart committed Oct 28, 2019
1 parent 96f1d0b commit fe238bd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,15 @@ X-Account-ID: 99
@/path/to/newthing.json
```

###### Add comments to the targets
###### Add comments

Lines starting with `#` are ignored.

```
# get a dragon ball
GET http://goku:9090/path/to/dragon?item=ball
# specify a test accout
X-Account-ID: 99
```

#### `-h2c`
Expand Down
2 changes: 2 additions & 0 deletions lib/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ func NewHTTPTargeter(src io.Reader, body []byte, hdr http.Header) Targeter {
for sc.Scan() {
if line = strings.TrimSpace(sc.Text()); line == "" {
break
} else if strings.HasPrefix(line, "#") {
continue
} else if strings.HasPrefix(line, "@") {
if tgt.Body, err = ioutil.ReadFile(line[1:]); err != nil {
return fmt.Errorf("bad body: %s", err)
Expand Down
16 changes: 16 additions & 0 deletions lib/targets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,13 @@ func TestNewHTTPTargeter(t *testing.T) {
GET http://:6060/
X-Header: 1
X-Header: 2`,
`
GET http://:8000/
# This is a comment. Lines starting with hash pound are ignored even inside the target.
X-Header: 1
# Another comment.
X-Header: 2`,
)

src := bytes.NewBufferString(strings.TrimSpace(targets))
Expand Down Expand Up @@ -374,6 +381,15 @@ func TestNewHTTPTargeter(t *testing.T) {
"Content-Type": []string{"text/plain"},
},
},
{
Method: "GET",
URL: "http://:8000/",
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 fe238bd

Please sign in to comment.