769735c2 by astaxie

fix #166

1 parent b114f258
...@@ -74,15 +74,25 @@ func (ctx *Context) SetCookie(name string, value string, others ...interface{}) ...@@ -74,15 +74,25 @@ 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 if others[0].(int) > 0 {
77 fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int)) 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:
83 if others[0].(int64) > 0 {
79 fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int64)) 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:
89 if others[0].(int32) > 0 {
81 fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int32)) 90 fmt.Fprintf(&b, "; Max-Age=%d", others[0].(int32))
82 } 91 } else if others[0].(int32) < 0 {
83 } else {
84 fmt.Fprintf(&b, "; Max-Age=0") 92 fmt.Fprintf(&b, "; Max-Age=0")
85 } 93 }
94 }
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)))
88 } 98 }
......
...@@ -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
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!