mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
This commit is contained in:
parent
72c5d2882b
commit
352b297977
12
iris.go
12
iris.go
|
@ -219,6 +219,11 @@ func New(cfg ...config.Iris) *Framework {
|
||||||
},
|
},
|
||||||
engines: make([]*templateEngineWrapper, 0),
|
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
|
// set the websocket server
|
||||||
s.Websocket = NewWebsocketServer(s.Config.Websocket)
|
s.Websocket = NewWebsocketServer(s.Config.Websocket)
|
||||||
// set the servemux, which will provide us the public API also, with its context pool
|
// 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() {
|
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
|
// prepare the response engines, if no response engines setted for the default content-types
|
||||||
// then add them
|
// 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.
|
s.Logger.Panic(err) // panic on templates loading before listening if we have an error.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// listen to websocket connections
|
// listen to websocket connections
|
||||||
RegisterWebsocketServer(s, s.Websocket, s.Logger)
|
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.
|
// Note: Don't worry if no session database is registered, your context.Session will continue to work.
|
||||||
func (s *Framework) UseSessionDB(db SessionDatabase) {
|
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
|
// UseResponse accepts a ResponseEngine and the key or content type on which the developer wants to register this response engine
|
||||||
|
|
|
@ -267,13 +267,13 @@ type (
|
||||||
// sessionsManager implements the ISessionsManager interface
|
// sessionsManager implements the ISessionsManager interface
|
||||||
// contains the cookie's name, the provider and a duration for GC and cookie life expire
|
// contains the cookie's name, the provider and a duration for GC and cookie life expire
|
||||||
sessionsManager struct {
|
sessionsManager struct {
|
||||||
config config.Sessions
|
config *config.Sessions
|
||||||
provider *sessionProvider
|
provider *sessionProvider
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// newSessionsManager creates & returns a new SessionsManager and start its GC
|
// 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 {
|
if c.DecodeCookie {
|
||||||
c.Cookie = base64.URLEncoding.EncodeToString([]byte(c.Cookie)) // change the cookie's name/key to a more safe(?)
|
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:
|
// get the real value for your tests by:
|
||||||
|
@ -285,6 +285,11 @@ func newSessionsManager(c config.Sessions) *sessionsManager {
|
||||||
return manager
|
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 {
|
func (m *sessionsManager) generateSessionID() string {
|
||||||
return base64.URLEncoding.EncodeToString(utils.Random(32))
|
return base64.URLEncoding.EncodeToString(utils.Random(32))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user