fix #166
Showing
2 changed files
with
18 additions
and
8 deletions
| ... | @@ -74,14 +74,24 @@ func (ctx *Context) SetCookie(name string, value string, others ...interface{}) | ... | @@ -74,14 +74,24 @@ func (ctx *Context) SetCookie(name string, value string, others ...interface{}) |
| 74 | if len(others) > 0 { | 74 | if len(others) > 0 { |
| 75 | switch others[0].(type) { | 75 | switch others[0].(type) { |
| 76 | case int: | 76 | case int: |
| 77 | fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int)) | 77 | if others[0].(int) > 0 { |
| 78 | fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int)) | ||
| 79 | } else if others[0].(int) < 0 { | ||
| 80 | fmt.Fprintf(&b, "; Max-Age=0") | ||
| 81 | } | ||
| 78 | case int64: | 82 | case int64: |
| 79 | fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int64)) | 83 | if others[0].(int64) > 0 { |
| 84 | fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int64)) | ||
| 85 | } else if others[0].(int64) < 0 { | ||
| 86 | fmt.Fprintf(&b, "; Max-Age=0") | ||
| 87 | } | ||
| 80 | case int32: | 88 | case int32: |
| 81 | fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int32)) | 89 | if others[0].(int32) > 0 { |
| 90 | fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int32)) | ||
| 91 | } else if others[0].(int32) < 0 { | ||
| 92 | fmt.Fprintf(&b, "; Max-Age=0") | ||
| 93 | } | ||
| 82 | } | 94 | } |
| 83 | } else { | ||
| 84 | fmt.Fprintf(&b, "; Max-Age=0") | ||
| 85 | } | 95 | } |
| 86 | if len(others) > 1 { | 96 | if len(others) > 1 { |
| 87 | fmt.Fprintf(&b, "; Path=%s", sanitizeValue(others[1].(string))) | 97 | fmt.Fprintf(&b, "; Path=%s", sanitizeValue(others[1].(string))) | ... | ... |
| ... | @@ -54,7 +54,8 @@ func ReadFromRequest(c *Controller) *FlashData { | ... | @@ -54,7 +54,8 @@ func ReadFromRequest(c *Controller) *FlashData { |
| 54 | Data: make(map[string]string), | 54 | Data: make(map[string]string), |
| 55 | } | 55 | } |
| 56 | if cookie, err := c.Ctx.Request.Cookie("BEEGO_FLASH"); err == nil { | 56 | if cookie, err := c.Ctx.Request.Cookie("BEEGO_FLASH"); err == nil { |
| 57 | vals := strings.Split(cookie.Value, "\x00") | 57 | v, _ := url.QueryUnescape(cookie.Value) |
| 58 | vals := strings.Split(v, "\x00") | ||
| 58 | for _, v := range vals { | 59 | for _, v := range vals { |
| 59 | if len(v) > 0 { | 60 | if len(v) > 0 { |
| 60 | kv := strings.Split(v, ":") | 61 | kv := strings.Split(v, ":") |
| ... | @@ -64,8 +65,7 @@ func ReadFromRequest(c *Controller) *FlashData { | ... | @@ -64,8 +65,7 @@ func ReadFromRequest(c *Controller) *FlashData { |
| 64 | } | 65 | } |
| 65 | } | 66 | } |
| 66 | //read one time then delete it | 67 | //read one time then delete it |
| 67 | cookie.MaxAge = -1 | 68 | c.Ctx.SetCookie("BEEGO_FLASH", "", -1) |
| 68 | c.Ctx.Request.AddCookie(cookie) | ||
| 69 | } | 69 | } |
| 70 | c.Data["flash"] = flash.Data | 70 | c.Data["flash"] = flash.Data |
| 71 | return flash | 71 | return flash | ... | ... |
-
Please register or sign in to post a comment