
* upgrade to latest ruff * try to fix dep review * try to fix dep review (2) * upgrade black * upgrade black (2) * update allowed dependencies * update allowed dependencies (2) * update allowed dependencies (3) * wait between interim and final in yield test * remove previous commit, increase delay between yield * forgot to save on the time.sleep(1) removal * fix integration (maybe?) * fix pyi? * what even is going on * what is realityi? * test another fix for app harness * try to wait even longer? * force uvloop to be optional * downpin fastapi < 0.111, remove changes to test
49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
"""Base Reflex middleware."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from abc import ABC
|
|
from typing import TYPE_CHECKING, Optional
|
|
|
|
from reflex.base import Base
|
|
from reflex.event import Event
|
|
from reflex.state import BaseState, StateUpdate
|
|
|
|
if TYPE_CHECKING:
|
|
from reflex.app import App
|
|
|
|
|
|
class Middleware(Base, ABC):
|
|
"""Middleware to preprocess and postprocess requests."""
|
|
|
|
async def preprocess(
|
|
self, app: App, state: BaseState, event: Event
|
|
) -> Optional[StateUpdate]:
|
|
"""Preprocess the event.
|
|
|
|
Args:
|
|
app: The app.
|
|
state: The client state.
|
|
event: The event to preprocess.
|
|
|
|
Returns:
|
|
An optional state update to return.
|
|
"""
|
|
return None
|
|
|
|
async def postprocess(
|
|
self, app: App, state: BaseState, event: Event, update: StateUpdate
|
|
) -> StateUpdate:
|
|
"""Postprocess the event.
|
|
|
|
Args:
|
|
app: The app.
|
|
state: The client state.
|
|
event: The event to postprocess.
|
|
update: The current state update.
|
|
|
|
Returns:
|
|
An optional state to return.
|
|
"""
|
|
return update
|