Replace wrapper-based SessionMiddleware/OIDCApp with KayaMixin subclasses applied via KayaApp(mixins=[...]). Mixins hook into handle_request and handle_websocket via before/after hooks, so both ASGI and RSGI keep working. Mixin dependencies are applied automatically and deduplicated.
24 lines
646 B
Python
24 lines
646 B
Python
from kaya.core import HttpContext, KayaApp
|
|
from kaya.session import InMemorySessionStore, SessionMixin
|
|
|
|
app = KayaApp(mixins=[SessionMixin(InMemorySessionStore())])
|
|
|
|
|
|
@app.GET('/')
|
|
async def home(ctx: HttpContext) -> None:
|
|
visits = ctx.session.get('visits', 0) + 1
|
|
ctx.session['visits'] = visits
|
|
await ctx.send_str(200, f'visits: {visits}')
|
|
|
|
|
|
@app.GET('/read')
|
|
async def read(ctx: HttpContext) -> None:
|
|
visits = ctx.session.get('visits', 0)
|
|
await ctx.send_str(200, f'visits: {visits}')
|
|
|
|
|
|
@app.GET('/clear')
|
|
async def clear(ctx: HttpContext) -> None:
|
|
ctx.session.invalidate()
|
|
await ctx.send_str(200, 'session cleared')
|