Esempio n. 1
0
// Cookie implements `engine.Request#Cookie` function.
func (r *Request) Cookie(name string) (engine.Cookie, error) {
	c := new(fasthttp.Cookie)
	c.SetKey(name)
	b := r.Request.Header.Cookie(name)
	if b == nil {
		return nil, echo.ErrCookieNotFound
	}
	c.ParseBytes(b)
	return &Cookie{c}, nil
}
// Cookies implements `engine.Request#Cookies` function.
func (r *Request) Cookies() []engine.Cookie {
	cookies := make([]engine.Cookie, 0)
	r.Request.Header.VisitAllCookie(func(name, value []byte) {
		c := new(fasthttp.Cookie)
		c.SetKey(string(name))
		c.ParseBytes(value)
		cookies = append(cookies, &Cookie{c})
	})
	return cookies
}
Esempio n. 3
0
// Cookies implements `engine.Request#Cookies` function.
func (r *Request) Cookies() []engine.Cookie {
	var cookies []engine.Cookie
	i := 0
	r.Request.Header.VisitAllCookie(func(name, value []byte) {
		c := new(fasthttp.Cookie)
		c.SetKey(string(name))
		c.ParseBytes(value)
		cookies[i] = &Cookie{c}
	})
	return cookies
}