From d7a5281bda6ab38f7d9338f3f163aec2f64de0b3 Mon Sep 17 00:00:00 2001 From: astaxie Date: Mon, 4 Aug 2014 16:21:06 +0800 Subject: [PATCH] session: support cookie domain --- beego.go | 1 + config.go | 1 + session/session.go | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/beego.go b/beego.go index 8dbed61b..c993cfe0 100644 --- a/beego.go +++ b/beego.go @@ -362,6 +362,7 @@ func initBeforeHttpRun() { `"sessionIDHashFunc":"` + SessionHashFunc + `",` + `"sessionIDHashKey":"` + SessionHashKey + `",` + `"enableSetCookie":` + strconv.FormatBool(SessionAutoSetCookie) + `,` + + `"domain":` + SessionDomain + `,` + `"cookieLifeTime":` + strconv.Itoa(SessionCookieLifeTime) + `}` } GlobalSessions, err = session.NewManager(SessionProvider, diff --git a/config.go b/config.go index 55290cd5..98109779 100644 --- a/config.go +++ b/config.go @@ -55,6 +55,7 @@ var ( SessionHashKey string // session hash salt string. SessionCookieLifeTime int // the life time of session id in cookie. SessionAutoSetCookie bool // auto setcookie + SessionDomain string // the cookie domain default is empty UseFcgi bool MaxMemory int64 EnableGzip bool // flag of enable gzip diff --git a/session/session.go b/session/session.go index 04ecb986..35d81b6e 100644 --- a/session/session.go +++ b/session/session.go @@ -72,6 +72,7 @@ type managerConfig struct { SessionIDHashKey string `json:"sessionIDHashKey"` CookieLifeTime int `json:"cookieLifeTime"` ProviderConfig string `json:"providerConfig"` + Domain string `json:"domain"` } // Manager contains Provider and its configuration. @@ -134,7 +135,8 @@ func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (se Value: url.QueryEscape(sid), Path: "/", HttpOnly: true, - Secure: manager.config.Secure} + Secure: manager.config.Secure, + Domain: manager.config.Domain} if manager.config.CookieLifeTime >= 0 { cookie.MaxAge = manager.config.CookieLifeTime } @@ -153,7 +155,8 @@ func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (se Value: url.QueryEscape(sid), Path: "/", HttpOnly: true, - Secure: manager.config.Secure} + Secure: manager.config.Secure, + Domain: manager.config.Domain} if manager.config.CookieLifeTime >= 0 { cookie.MaxAge = manager.config.CookieLifeTime } @@ -208,6 +211,7 @@ func (manager *Manager) SessionRegenerateId(w http.ResponseWriter, r *http.Reque Path: "/", HttpOnly: true, Secure: manager.config.Secure, + Domain: manager.config.Domain, } } else { oldsid, _ := url.QueryUnescape(cookie.Value)