Initial project import

This commit is contained in:
Agila Forge Importer committed 2026-07-13 15:20:32 +00:00
commit 23f2d29e32
11957 files changed
+1754577

No files matched your search

@@ -0,0 +1,33 @@
module veb_middleware
import x.sessions
import veb
// create can be used to add session middleware to your veb app to ensure
// a valid session always exists. If a valid session exists the session data will
// be loaded into `session_data`, else a new session id will be generated.
// You have to pass the Context type as the generic type.
pub fn create[T, X](mut s sessions.Sessions[T]) veb.MiddlewareOptions[X] {
return veb.MiddlewareOptions[X]{
handler: fn [mut s] [T, X](mut ctx X) bool {
// a session id is retrieved from the client, so it must be considered
// untrusted and has to be verified on every request
sid, valid := s.validate_session(ctx)
if !valid {
if s.save_uninitialized {
// invalid session id, so create a new one
s.set_session_id(mut ctx)
}
return true
}
ctx.CurrentSession.session_id = sid
if data := s.store.get(sid, s.max_age) {
ctx.CurrentSession.session_data = data
}
return true
}
}
}