diff --git a/context.go b/context.go index a93e3f77..3b3c7c15 100644 --- a/context.go +++ b/context.go @@ -74,14 +74,24 @@ func (ctx *Context) SetCookie(name string, value string, others ...interface{}) if len(others) > 0 { switch others[0].(type) { case int: - fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int)) + if others[0].(int) > 0 { + fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int)) + } else if others[0].(int) < 0 { + fmt.Fprintf(&b, "; Max-Age=0") + } case int64: - fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int64)) + if others[0].(int64) > 0 { + fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int64)) + } else if others[0].(int64) < 0 { + fmt.Fprintf(&b, "; Max-Age=0") + } case int32: - fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int32)) + if others[0].(int32) > 0 { + fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int32)) + } else if others[0].(int32) < 0 { + fmt.Fprintf(&b, "; Max-Age=0") + } } - } else { - fmt.Fprintf(&b, "; Max-Age=0") } if len(others) > 1 { fmt.Fprintf(&b, "; Path=%s", sanitizeValue(others[1].(string))) diff --git a/flash.go b/flash.go index 927a2225..dc26a984 100644 --- a/flash.go +++ b/flash.go @@ -54,7 +54,8 @@ func ReadFromRequest(c *Controller) *FlashData { Data: make(map[string]string), } if cookie, err := c.Ctx.Request.Cookie("BEEGO_FLASH"); err == nil { - vals := strings.Split(cookie.Value, "\x00") + v, _ := url.QueryUnescape(cookie.Value) + vals := strings.Split(v, "\x00") for _, v := range vals { if len(v) > 0 { kv := strings.Split(v, ":") @@ -64,8 +65,7 @@ func ReadFromRequest(c *Controller) *FlashData { } } //read one time then delete it - cookie.MaxAge = -1 - c.Ctx.Request.AddCookie(cookie) + c.Ctx.SetCookie("BEEGO_FLASH", "", -1) } c.Data["flash"] = flash.Data return flash