mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 17:40:55 +00:00
session support secure set
This commit is contained in:
parent
f9ed74a9b2
commit
2249d745d9
@ -44,15 +44,16 @@ type Manager struct {
|
|||||||
cookieName string //private cookiename
|
cookieName string //private cookiename
|
||||||
provider Provider
|
provider Provider
|
||||||
maxlifetime int64
|
maxlifetime int64
|
||||||
|
options []interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewManager(provideName, cookieName string, maxlifetime int64, savePath string) (*Manager, error) {
|
func NewManager(provideName, cookieName string, maxlifetime int64, savePath string, options ...interface{}) (*Manager, error) {
|
||||||
provider, ok := provides[provideName]
|
provider, ok := provides[provideName]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("session: unknown provide %q (forgotten import?)", provideName)
|
return nil, fmt.Errorf("session: unknown provide %q (forgotten import?)", provideName)
|
||||||
}
|
}
|
||||||
provider.SessionInit(maxlifetime, savePath)
|
provider.SessionInit(maxlifetime, savePath)
|
||||||
return &Manager{provider: provider, cookieName: cookieName, maxlifetime: maxlifetime}, nil
|
return &Manager{provider: provider, cookieName: cookieName, maxlifetime: maxlifetime, options: options}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//get Session
|
//get Session
|
||||||
@ -61,11 +62,15 @@ func (manager *Manager) SessionStart(w http.ResponseWriter, r *http.Request) (se
|
|||||||
if err != nil || cookie.Value == "" {
|
if err != nil || cookie.Value == "" {
|
||||||
sid := manager.sessionId()
|
sid := manager.sessionId()
|
||||||
session, _ = manager.provider.SessionRead(sid)
|
session, _ = manager.provider.SessionRead(sid)
|
||||||
|
secure := false
|
||||||
|
if len(manager.options) > 0 {
|
||||||
|
secure = manager.options[0].(bool)
|
||||||
|
}
|
||||||
cookie := http.Cookie{Name: manager.cookieName,
|
cookie := http.Cookie{Name: manager.cookieName,
|
||||||
Value: url.QueryEscape(sid),
|
Value: url.QueryEscape(sid),
|
||||||
Path: "/",
|
Path: "/",
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Secure: false}
|
Secure: secure}
|
||||||
//cookie.Expires = time.Now().Add(time.Duration(manager.maxlifetime) * time.Second)
|
//cookie.Expires = time.Now().Add(time.Duration(manager.maxlifetime) * time.Second)
|
||||||
http.SetCookie(w, &cookie)
|
http.SetCookie(w, &cookie)
|
||||||
r.AddCookie(&cookie)
|
r.AddCookie(&cookie)
|
||||||
|
Loading…
Reference in New Issue
Block a user