glimr/http/middleware/start_session

Start Session Middleware

Handles the full session lifecycle for each request: reads or creates session from cookie, starts the actor, calls the handler, then persists changes and sets the cookie on the response.

Values

pub fn run(
  req: request.Request(wisp.Connection),
  next: fn(request.Request(wisp.Connection), session.Session) -> response.Response(
    wisp.Body,
  ),
) -> response.Response(wisp.Body)

Starts a session for the current request. Reads the session cookie, loads data from the configured store, and provides a live session to the next handler. After the handler returns, persists changes and sets the cookie on the response.

Usage in kernel middleware:

use req, session <- start_session.run(req)
let ctx = Context(..ctx, session: session)
router(req, ctx)
Search Document