mirror of
https://github.com/kataras/iris.git
synced 2025-03-14 08:16:28 +01:00
Replace fasthttp's with correct remove cookie code... fixes flash messages and sessions on some cases
This commit is contained in:
parent
6761d58e53
commit
68111f57d1
11
context.go
11
context.go
|
@ -744,8 +744,15 @@ func (ctx *Context) SetCookieKV(key, value string) {
|
||||||
|
|
||||||
// RemoveCookie deletes a cookie by it's name/key
|
// RemoveCookie deletes a cookie by it's name/key
|
||||||
func (ctx *Context) RemoveCookie(name string) {
|
func (ctx *Context) RemoveCookie(name string) {
|
||||||
ctx.RequestCtx.Request.Header.DelCookie(name)
|
cookie := fasthttp.AcquireCookie()
|
||||||
ctx.RequestCtx.Response.Header.DelClientCookie(name)
|
cookie.SetKey(name)
|
||||||
|
cookie.SetValue("")
|
||||||
|
cookie.SetPath("/")
|
||||||
|
cookie.SetHTTPOnly(true)
|
||||||
|
exp := time.Now().Add(-time.Duration(1) * time.Minute) //RFC says 1 second, but make sure 1 minute because we are using fasthttp
|
||||||
|
cookie.SetExpire(exp)
|
||||||
|
ctx.Response.Header.SetCookie(cookie)
|
||||||
|
fasthttp.ReleaseCookie(cookie)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFlashes returns all the flash messages for available for this request
|
// GetFlashes returns all the flash messages for available for this request
|
||||||
|
|
|
@ -427,8 +427,13 @@ func TestContextFlashMessages(t *testing.T) {
|
||||||
// get the first flash, the next should be avaiable to the next requess
|
// get the first flash, the next should be avaiable to the next requess
|
||||||
Get("/get_first_flash", func(ctx *Context) {
|
Get("/get_first_flash", func(ctx *Context) {
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
val, _ := ctx.GetFlash(v.Key)
|
val, err := ctx.GetFlash(v.Key)
|
||||||
ctx.JSON(StatusOK, map[string]string{v.Key: val})
|
if err == nil {
|
||||||
|
ctx.JSON(StatusOK, map[string]string{v.Key: val})
|
||||||
|
} else {
|
||||||
|
ctx.JSON(StatusOK, nil) // return nil
|
||||||
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -516,6 +521,12 @@ func TestContextFlashMessages(t *testing.T) {
|
||||||
g.JSON().Null()
|
g.JSON().Null()
|
||||||
g.Cookies().Empty()
|
g.Cookies().Empty()
|
||||||
|
|
||||||
|
// test Get, and get again should return nothing
|
||||||
|
e.PUT("/set").Expect().Status(StatusOK).Cookies().NotEmpty()
|
||||||
|
e.GET("/get_first_flash").Expect().Status(StatusOK).JSON().Object().ContainsKey(firstKey).NotContainsKey(lastKey)
|
||||||
|
g = e.GET("/get_first_flash").Expect().Status(StatusOK)
|
||||||
|
g.JSON().Null()
|
||||||
|
g.Cookies().Empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContextSessions(t *testing.T) {
|
func TestContextSessions(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user