Skip to content

Commit

Permalink
Added method "Cookie" for dynamic HTTP response
Browse files Browse the repository at this point in the history
Usage:

```
sonar http new -p test -c 200 -P /test -d '{{ .Cookie "test" }}'
```
  • Loading branch information
anton.prokhorov committed Apr 8, 2024
1 parent e6e54d7 commit 626600e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/httpdb/httpdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ func (d *Data) Header(key string) string {
return d.r.Header.Get(key)
}

func (d *Data) Cookie(key string) string {
c, err := d.r.Cookie(key)
if err != nil {
return ""
}
return c.Value

Check warning on line 156 in internal/httpdb/httpdb.go

View check run for this annotation

Codecov / codecov/patch

internal/httpdb/httpdb.go#L151-L156

Added lines #L151 - L156 were not covered by tests
}

func renderTemplate(t string, data interface{}) (string, error) {
tpl, err := template.New("").Parse(t)
if err != nil {
Expand Down

0 comments on commit 626600e

Please sign in to comment.