Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix comments between headers (#447) #448

Merged
merged 1 commit into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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