diff --git a/README.md b/README.md index 32126c5c..267a54b4 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/lib/targets.go b/lib/targets.go index d3b87907..86f2ef72 100644 --- a/lib/targets.go +++ b/lib/targets.go @@ -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) diff --git a/lib/targets_test.go b/lib/targets_test.go index a1a8d8e8..473ce19d 100644 --- a/lib/targets_test.go +++ b/lib/targets_test.go @@ -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)) @@ -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 {