[add] support for retrieving cookies in sui Request struct
This commit is contained in:
parent
00f10cd630
commit
a1de910337
3 changed files with 17 additions and 1 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -39,4 +39,5 @@ xgen/v1.0/*
|
|||
!xgen/v1.0/layouts__index.async.js
|
||||
!pipe/ui
|
||||
*-unit-test
|
||||
docker/build/test
|
||||
docker/build/test
|
||||
db
|
||||
|
|
@ -213,6 +213,7 @@ func (r *Request) Render() (string, int, error) {
|
|||
data["$payload"] = r.Request.Payload
|
||||
data["$query"] = r.Request.Query
|
||||
data["$param"] = r.Request.Params
|
||||
data["$cookie"] = r.Request.Cookies()
|
||||
data["$url"] = r.Request.URL
|
||||
|
||||
printData := false
|
||||
|
|
|
|||
|
|
@ -40,6 +40,20 @@ func NewRequestMock(mock *PageMock) *Request {
|
|||
}
|
||||
}
|
||||
|
||||
// Cookies get the cookies
|
||||
func (r *Request) Cookies() map[string]string {
|
||||
cookies := map[string]string{}
|
||||
cookie := r.Headers.Get("Cookie")
|
||||
parts := strings.Split(cookie, ";")
|
||||
for _, part := range parts {
|
||||
kv := strings.Split(strings.TrimSpace(part), "=")
|
||||
if len(kv) == 2 {
|
||||
cookies[kv[0]] = kv[1]
|
||||
}
|
||||
}
|
||||
return cookies
|
||||
}
|
||||
|
||||
// ExecString get the data
|
||||
func (r *Request) ExecString(data string) (Data, error) {
|
||||
var res Data
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue