Skip to content

Commit

Permalink
Added method "Cookie" for dynamic HTTP response (#162)
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
nt0xa authored Apr 8, 2024
1 parent e6e54d7 commit b6b95af
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
}

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

0 comments on commit b6b95af

Please sign in to comment.