Gerasimos Maropoulos 2016-07-20 20:23:54 +03:00
parent 72c5d2882b
commit 352b297977
2 changed files with 13 additions and 8 deletions

12
iris.go
View File

@ -219,6 +219,11 @@ func New(cfg ...config.Iris) *Framework {
},
engines: make([]*templateEngineWrapper, 0),
}
// set the sessions
if s.Config.Sessions.Cookie != "" {
//set the session manager
s.sessions = newSessionsManager(&s.Config.Sessions)
}
// set the websocket server
s.Websocket = NewWebsocketServer(s.Config.Websocket)
// set the servemux, which will provide us the public API also, with its context pool
@ -234,10 +239,6 @@ func New(cfg ...config.Iris) *Framework {
}
func (s *Framework) initialize() {
if s.Config.Sessions.Cookie != "" {
//set the session manager
s.sessions = newSessionsManager(s.Config.Sessions)
}
// prepare the response engines, if no response engines setted for the default content-types
// then add them
@ -275,7 +276,6 @@ func (s *Framework) initialize() {
s.Logger.Panic(err) // panic on templates loading before listening if we have an error.
}
}
// listen to websocket connections
RegisterWebsocketServer(s, s.Websocket, s.Logger)
@ -528,7 +528,7 @@ func UseSessionDB(db SessionDatabase) {
//
// Note: Don't worry if no session database is registered, your context.Session will continue to work.
func (s *Framework) UseSessionDB(db SessionDatabase) {
s.sessions.provider.registerDatabase(db)
s.sessions.registerDatabase(db)
}
// UseResponse accepts a ResponseEngine and the key or content type on which the developer wants to register this response engine

View File

@ -267,13 +267,13 @@ type (
// sessionsManager implements the ISessionsManager interface
// contains the cookie's name, the provider and a duration for GC and cookie life expire
sessionsManager struct {
config config.Sessions
config *config.Sessions
provider *sessionProvider
}
)
// newSessionsManager creates & returns a new SessionsManager and start its GC
func newSessionsManager(c config.Sessions) *sessionsManager {
func newSessionsManager(c *config.Sessions) *sessionsManager {
if c.DecodeCookie {
c.Cookie = base64.URLEncoding.EncodeToString([]byte(c.Cookie)) // change the cookie's name/key to a more safe(?)
// get the real value for your tests by:
@ -285,6 +285,11 @@ func newSessionsManager(c config.Sessions) *sessionsManager {
return manager
}
func (m *sessionsManager) registerDatabase(db SessionDatabase) {
m.provider.expires = m.config.Expires // updae the expires confiuration field for any case
m.provider.registerDatabase(db)
}
func (m *sessionsManager) generateSessionID() string {
return base64.URLEncoding.EncodeToString(utils.Random(32))
}