From a95d6f39f16600f3bb780af607cf5587fc05a142 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 8 Apr 2013 12:50:11 +0800 Subject: [PATCH] fix session cookies's expirded --- session/session.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/session/session.go b/session/session.go index 71756139..6551646a 100644 --- a/session/session.go +++ b/session/session.go @@ -61,9 +61,17 @@ func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (se if err != nil || cookie.Value == "" { sid := manager.sessionId() session, _ = manager.provider.SessionRead(sid) - cookie := http.Cookie{Name: manager.cookieName, Value: url.QueryEscape(sid), Path: "/", HttpOnly: true, MaxAge: int(manager.maxlifetime)} + cookie := http.Cookie{Name: manager.cookieName, + Value: url.QueryEscape(sid), + Path: "/", + HttpOnly: true, + Secure: true} + cookie.Expires = time.Now().Add(time.Duration(manager.maxlifetime) * time.Second) http.SetCookie(w, &cookie) + r.AddCookie(&cookie) } else { + cookie.Expires = time.Now().Add(time.Duration(manager.maxlifetime) * time.Second) + http.SetCookie(w, cookie) sid, _ := url.QueryUnescape(cookie.Value) session, _ = manager.provider.SessionRead(sid) }