add check of global sessionOn to prevent nil pointer panic: sessionOn of router is set to false while global sessionOn is false

This commit is contained in:
AllenX2018 2020-11-24 11:22:07 +08:00
parent 963de3e68b
commit 7d7c4539d3

View File

@ -781,8 +781,12 @@ func (p *ControllerRegister) serveHttp(ctx *beecontext.Context) {
currentSessionOn = BConfig.WebConfig.Session.SessionOn
originRouterInfo, originFindRouter = p.FindRouter(ctx)
if originFindRouter {
if !currentSessionOn && originRouterInfo.sessionOn {
logs.Warn("global sessionOn is false, sessionOn of router [%s] %s can't be set to true", ctx.Request.Method, ctx.Request.URL.Path)
} else {
currentSessionOn = originRouterInfo.sessionOn
}
}
if currentSessionOn {
ctx.Input.CruSession, err = GlobalSessions.SessionStart(rw, r)
if err != nil {