1
0
의 미러 https://github.com/astaxie/beego.git synced 2025-07-17 18:52:16 +00:00

fix set cookies many times

This commit is contained in:
astaxie
2013-05-07 15:36:43 +08:00
부모 18bf474951
커밋 6af2778ab9
2개의 변경된 파일29개의 추가작업 그리고 20개의 파일을 삭제

파일 보기

@@ -66,6 +66,6 @@ func (ctx *Context) SetCookie(name string, value string, age int64) {
} else {
utctime = time.Unix(time.Now().Unix()+age, 0)
}
cookie := fmt.Sprintf("%s=%s; expires=%s", name, value, webTime(utctime))
ctx.SetHeader("Set-Cookie", cookie, false)
cookie := fmt.Sprintf("%s=%s; Expires=%s; Path=/", name, value, webTime(utctime))
ctx.SetHeader("Set-Cookie", cookie, true)
}

파일 보기

@@ -21,12 +21,13 @@ import (
)
type Controller struct {
Ctx *Context
Data map[interface{}]interface{}
ChildName string
TplNames string
Layout string
TplExt string
Ctx *Context
Data map[interface{}]interface{}
ChildName string
TplNames string
Layout string
TplExt string
CruSession session.SessionStore
}
type ControllerInterface interface {
@@ -58,6 +59,9 @@ func (c *Controller) Prepare() {
}
func (c *Controller) Finish() {
if c.CruSession != nil {
c.CruSession.SessionRelease()
}
}
func (c *Controller) Get() {
@@ -259,25 +263,30 @@ func (c *Controller) SaveToFile(fromfile, tofile string) error {
return nil
}
func (c *Controller) StartSession() (sess session.SessionStore) {
sess = GlobalSessions.SessionStart(c.Ctx.ResponseWriter, c.Ctx.Request)
return
func (c *Controller) StartSession() session.SessionStore {
if c.CruSession == nil {
c.CruSession = GlobalSessions.SessionStart(c.Ctx.ResponseWriter, c.Ctx.Request)
}
return c.CruSession
}
func (c *Controller) SetSession(name string, value interface{}) {
ss := c.StartSession()
defer ss.SessionRelease()
ss.Set(name, value)
if c.CruSession == nil {
c.StartSession()
}
c.CruSession.Set(name, value)
}
func (c *Controller) GetSession(name string) interface{} {
ss := c.StartSession()
defer ss.SessionRelease()
return ss.Get(name)
if c.CruSession == nil {
c.StartSession()
}
return c.CruSession.Get(name)
}
func (c *Controller) DelSession(name string) {
ss := c.StartSession()
defer ss.SessionRelease()
ss.Delete(name)
if c.CruSession == nil {
c.StartSession()
}
c.CruSession.Delete(name)
}