start sessions.... again
This commit is contained in:
parent
7b7876e864
commit
195800082a
|
@ -135,7 +135,7 @@ func (s *Server) processRequest(ctx *fasthttp.RequestCtx) {
|
|||
return
|
||||
} else if found {
|
||||
logger.Debug("Found Lua route match for %s %s with %d params", method, path, params.Count)
|
||||
s.handleLuaRoute(ctx, bytecode, scriptPath, params)
|
||||
s.handleLuaRoute(ctx, bytecode, scriptPath, params, method, path)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -152,13 +152,11 @@ func (s *Server) processRequest(ctx *fasthttp.RequestCtx) {
|
|||
}
|
||||
|
||||
// handleLuaRoute executes a Lua route
|
||||
func (s *Server) handleLuaRoute(ctx *fasthttp.RequestCtx, bytecode []byte, scriptPath string, params *routers.Params) {
|
||||
func (s *Server) handleLuaRoute(ctx *fasthttp.RequestCtx, bytecode []byte, scriptPath string, params *routers.Params, method string, path string) {
|
||||
// Create context for Lua execution
|
||||
luaCtx := runner.NewHTTPContext(ctx)
|
||||
defer luaCtx.Release()
|
||||
|
||||
method := string(ctx.Method())
|
||||
path := string(ctx.Path())
|
||||
host := string(ctx.Host())
|
||||
|
||||
// Set up additional context values
|
||||
|
@ -166,6 +164,13 @@ func (s *Server) handleLuaRoute(ctx *fasthttp.RequestCtx, bytecode []byte, scrip
|
|||
luaCtx.Set("path", path)
|
||||
luaCtx.Set("host", host)
|
||||
|
||||
// Add session data
|
||||
session := s.sessionManager.GetSessionFromRequest(ctx)
|
||||
luaCtx.Set("session", map[string]any{
|
||||
"id": session.ID,
|
||||
"data": session.Data,
|
||||
})
|
||||
|
||||
// URL parameters
|
||||
if params.Count > 0 {
|
||||
paramMap := make(map[string]any, params.Count)
|
||||
|
|
|
@ -139,19 +139,12 @@ func (s *Sandbox) Execute(state *luajit.State, bytecode []byte, ctx *Context) (*
|
|||
|
||||
// extractResponseData pulls response info from the Lua state
|
||||
func extractHTTPResponseData(state *luajit.State, response *Response) {
|
||||
state.GetGlobal("__http_responses")
|
||||
state.GetGlobal("__http_response")
|
||||
if !state.IsTable(-1) {
|
||||
state.Pop(1)
|
||||
return
|
||||
}
|
||||
|
||||
state.PushNumber(1)
|
||||
state.GetTable(-2)
|
||||
if !state.IsTable(-1) {
|
||||
state.Pop(2)
|
||||
return
|
||||
}
|
||||
|
||||
// Extract status
|
||||
state.GetField(-1, "status")
|
||||
if state.IsNumber(-1) {
|
||||
|
@ -200,8 +193,7 @@ func extractHTTPResponseData(state *luajit.State, response *Response) {
|
|||
}
|
||||
state.Pop(1)
|
||||
|
||||
// Clean up
|
||||
state.Pop(2)
|
||||
state.Pop(1) // Pop __http_response
|
||||
}
|
||||
|
||||
// extractCookie pulls cookie data from the current table on the stack
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package sessions
|
||||
|
||||
import (
|
||||
"maps"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
@ -66,9 +67,7 @@ func (s *Session) GetAll() map[string]any {
|
|||
defer s.mu.RUnlock()
|
||||
|
||||
copy := make(map[string]any, len(s.Data))
|
||||
for k, v := range s.Data {
|
||||
copy[k] = v
|
||||
}
|
||||
maps.Copy(copy, s.Data)
|
||||
|
||||
return copy
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user