session: support cookie domain
Showing
3 changed files
with
8 additions
and
2 deletions
| ... | @@ -362,6 +362,7 @@ func initBeforeHttpRun() { | ... | @@ -362,6 +362,7 @@ func initBeforeHttpRun() { |
| 362 | `"sessionIDHashFunc":"` + SessionHashFunc + `",` + | 362 | `"sessionIDHashFunc":"` + SessionHashFunc + `",` + |
| 363 | `"sessionIDHashKey":"` + SessionHashKey + `",` + | 363 | `"sessionIDHashKey":"` + SessionHashKey + `",` + |
| 364 | `"enableSetCookie":` + strconv.FormatBool(SessionAutoSetCookie) + `,` + | 364 | `"enableSetCookie":` + strconv.FormatBool(SessionAutoSetCookie) + `,` + |
| 365 | `"domain":` + SessionDomain + `,` + | ||
| 365 | `"cookieLifeTime":` + strconv.Itoa(SessionCookieLifeTime) + `}` | 366 | `"cookieLifeTime":` + strconv.Itoa(SessionCookieLifeTime) + `}` |
| 366 | } | 367 | } |
| 367 | GlobalSessions, err = session.NewManager(SessionProvider, | 368 | GlobalSessions, err = session.NewManager(SessionProvider, | ... | ... |
| ... | @@ -55,6 +55,7 @@ var ( | ... | @@ -55,6 +55,7 @@ var ( |
| 55 | SessionHashKey string // session hash salt string. | 55 | SessionHashKey string // session hash salt string. |
| 56 | SessionCookieLifeTime int // the life time of session id in cookie. | 56 | SessionCookieLifeTime int // the life time of session id in cookie. |
| 57 | SessionAutoSetCookie bool // auto setcookie | 57 | SessionAutoSetCookie bool // auto setcookie |
| 58 | SessionDomain string // the cookie domain default is empty | ||
| 58 | UseFcgi bool | 59 | UseFcgi bool |
| 59 | MaxMemory int64 | 60 | MaxMemory int64 |
| 60 | EnableGzip bool // flag of enable gzip | 61 | EnableGzip bool // flag of enable gzip | ... | ... |
| ... | @@ -72,6 +72,7 @@ type managerConfig struct { | ... | @@ -72,6 +72,7 @@ type managerConfig struct { |
| 72 | SessionIDHashKey string `json:"sessionIDHashKey"` | 72 | SessionIDHashKey string `json:"sessionIDHashKey"` |
| 73 | CookieLifeTime int `json:"cookieLifeTime"` | 73 | CookieLifeTime int `json:"cookieLifeTime"` |
| 74 | ProviderConfig string `json:"providerConfig"` | 74 | ProviderConfig string `json:"providerConfig"` |
| 75 | Domain string `json:"domain"` | ||
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | // Manager contains Provider and its configuration. | 78 | // Manager contains Provider and its configuration. |
| ... | @@ -134,7 +135,8 @@ func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (se | ... | @@ -134,7 +135,8 @@ func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (se |
| 134 | Value: url.QueryEscape(sid), | 135 | Value: url.QueryEscape(sid), |
| 135 | Path: "/", | 136 | Path: "/", |
| 136 | HttpOnly: true, | 137 | HttpOnly: true, |
| 137 | Secure: manager.config.Secure} | 138 | Secure: manager.config.Secure, |
| 139 | Domain: manager.config.Domain} | ||
| 138 | if manager.config.CookieLifeTime >= 0 { | 140 | if manager.config.CookieLifeTime >= 0 { |
| 139 | cookie.MaxAge = manager.config.CookieLifeTime | 141 | cookie.MaxAge = manager.config.CookieLifeTime |
| 140 | } | 142 | } |
| ... | @@ -153,7 +155,8 @@ func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (se | ... | @@ -153,7 +155,8 @@ func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (se |
| 153 | Value: url.QueryEscape(sid), | 155 | Value: url.QueryEscape(sid), |
| 154 | Path: "/", | 156 | Path: "/", |
| 155 | HttpOnly: true, | 157 | HttpOnly: true, |
| 156 | Secure: manager.config.Secure} | 158 | Secure: manager.config.Secure, |
| 159 | Domain: manager.config.Domain} | ||
| 157 | if manager.config.CookieLifeTime >= 0 { | 160 | if manager.config.CookieLifeTime >= 0 { |
| 158 | cookie.MaxAge = manager.config.CookieLifeTime | 161 | cookie.MaxAge = manager.config.CookieLifeTime |
| 159 | } | 162 | } |
| ... | @@ -208,6 +211,7 @@ func (manager *Manager) SessionRegenerateId(w http.ResponseWriter, r *http.Reque | ... | @@ -208,6 +211,7 @@ func (manager *Manager) SessionRegenerateId(w http.ResponseWriter, r *http.Reque |
| 208 | Path: "/", | 211 | Path: "/", |
| 209 | HttpOnly: true, | 212 | HttpOnly: true, |
| 210 | Secure: manager.config.Secure, | 213 | Secure: manager.config.Secure, |
| 214 | Domain: manager.config.Domain, | ||
| 211 | } | 215 | } |
| 212 | } else { | 216 | } else { |
| 213 | oldsid, _ := url.QueryUnescape(cookie.Value) | 217 | oldsid, _ := url.QueryUnescape(cookie.Value) | ... | ... |
-
Please register or sign in to post a comment