mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Bring back AcquireCookie and ReleaseCookie usage
This commit is contained in:
parent
8f1bf8dcc7
commit
532254e03b
25
context.go
25
context.go
|
@ -790,22 +790,22 @@ func (ctx *Context) SetCookie(cookie *fasthttp.Cookie) {
|
|||
|
||||
// SetCookieKV adds a cookie, receives just a key(string) and a value(string)
|
||||
func (ctx *Context) SetCookieKV(key, value string) {
|
||||
//c := fasthttp.AcquireCookie()
|
||||
c := &fasthttp.Cookie{}
|
||||
c := fasthttp.AcquireCookie()
|
||||
// c := &fasthttp.Cookie{}
|
||||
c.SetKey(key)
|
||||
c.SetValue(value)
|
||||
c.SetHTTPOnly(true)
|
||||
c.SetExpire(time.Now().Add(time.Duration(120) * time.Minute))
|
||||
ctx.SetCookie(c)
|
||||
//fasthttp.ReleaseCookie(c)
|
||||
fasthttp.ReleaseCookie(c)
|
||||
}
|
||||
|
||||
// RemoveCookie deletes a cookie by it's name/key
|
||||
func (ctx *Context) RemoveCookie(name string) {
|
||||
ctx.Response.Header.DelCookie(name)
|
||||
|
||||
// cookie := fasthttp.AcquireCookie()
|
||||
cookie := &fasthttp.Cookie{}
|
||||
cookie := fasthttp.AcquireCookie()
|
||||
//cookie := &fasthttp.Cookie{}
|
||||
cookie.SetKey(name)
|
||||
cookie.SetValue("")
|
||||
cookie.SetPath("/")
|
||||
|
@ -813,7 +813,7 @@ func (ctx *Context) RemoveCookie(name string) {
|
|||
exp := time.Now().Add(-time.Duration(1) * time.Minute) //RFC says 1 second, but let's do it 1 minute to make sure is working...
|
||||
cookie.SetExpire(exp)
|
||||
ctx.SetCookie(cookie)
|
||||
//fasthttp.ReleaseCookie(cookie)
|
||||
fasthttp.ReleaseCookie(cookie)
|
||||
// delete request's cookie also, which is temporarly available
|
||||
ctx.Request.Header.DelCookie(name)
|
||||
}
|
||||
|
@ -911,25 +911,26 @@ func (ctx *Context) GetFlash(key string) (string, error) {
|
|||
func (ctx *Context) SetFlash(key string, value string) {
|
||||
cKey := flashMessageCookiePrefix + key
|
||||
cValue := base64.URLEncoding.EncodeToString([]byte(value))
|
||||
/* see https://github.com/kataras/iris/issues/351
|
||||
c := fasthttp.AcquireCookie() this occurs strange behavior if called inside a handler which ctx.Session() is already called for the first time
|
||||
|
||||
c := fasthttp.AcquireCookie()
|
||||
c.SetKey(cKey)
|
||||
c.SetValue(cValue)
|
||||
c.SetPath("/")
|
||||
c.SetHTTPOnly(true)
|
||||
ctx.RequestCtx.Response.Header.SetCookie(c)
|
||||
fasthttp.ReleaseCookie(c)
|
||||
*/
|
||||
// but this works, and the above:
|
||||
|
||||
// if any bug on the future: this works, and the above:
|
||||
//ctx.RequestCtx.Request.Header.SetCookie(cKey, cValue)
|
||||
//ctx.RequestCtx.Response.Header.Add("Set-Cookie", cKey+"="+cValue+"; Path:/; HttpOnly")
|
||||
//
|
||||
c := &fasthttp.Cookie{}
|
||||
|
||||
/*c := &fasthttp.Cookie{}
|
||||
c.SetKey(cKey)
|
||||
c.SetValue(cValue)
|
||||
c.SetPath("/")
|
||||
c.SetHTTPOnly(true)
|
||||
ctx.SetCookie(c)
|
||||
ctx.SetCookie(c)*/
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -332,8 +332,8 @@ func (m *sessionsManager) start(ctx *Context) *session {
|
|||
if cookieValue == "" { // cookie doesn't exists, let's generate a session and add set a cookie
|
||||
sid := m.generateSessionID()
|
||||
session = m.provider.init(sid)
|
||||
//cookie := fasthttp.AcquireCookie() strange errors when c.SetFlash (old)
|
||||
cookie := &fasthttp.Cookie{}
|
||||
cookie := fasthttp.AcquireCookie()
|
||||
//cookie := &fasthttp.Cookie{}
|
||||
// The RFC makes no mention of encoding url value, so here I think to encode both sessionid key and the value using the safe(to put and to use as cookie) url-encoding
|
||||
cookie.SetKey(m.config.Cookie)
|
||||
cookie.SetValue(sid)
|
||||
|
@ -377,6 +377,7 @@ func (m *sessionsManager) start(ctx *Context) *session {
|
|||
} // if it's -1 then the cookie is deleted when the browser closes
|
||||
|
||||
ctx.SetCookie(cookie)
|
||||
fasthttp.ReleaseCookie(cookie)
|
||||
} else {
|
||||
session = m.provider.read(cookieValue)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user