From b6b95af7a195ef55fc8461fef01e907357e7cd3b Mon Sep 17 00:00:00 2001 From: Anton Prokhorov Date: Mon, 8 Apr 2024 11:51:41 +0100 Subject: [PATCH] Added method "Cookie" for dynamic HTTP response (#162) Usage: ``` sonar http new -p test -c 200 -P /test -d '{{ .Cookie "test" }}' ``` --- internal/httpdb/httpdb.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/httpdb/httpdb.go b/internal/httpdb/httpdb.go index 53a3d33..d98cbde 100644 --- a/internal/httpdb/httpdb.go +++ b/internal/httpdb/httpdb.go @@ -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 {