StateMiddleware¶
- class gafaelfawr.middleware.state.StateMiddleware(app, *, cookie_name, state_class, parameters)¶
Bases:
BaseHTTPMiddleware
,Generic
Middleware to read and update an encrypted state cookie.
If a cookie by the given name exists, it will be parsed by the given class and stored as
request.state.cookie
. If anything in that object is changed as determined by an equality comparison, the state will be converted back to a cookie and set in the response after the request is complete.This middleware should run after
XForwardedMiddleware
since the results of that middleware are used to determine if the cookie should be marked as secure.- Parameters:
app (
FastAPI
) – The ASGI application.cookie_name (
str
) – The name of the state cookie.state_class (
type
[TypeVar
(T
, bound=BaseState
)]) – The class to use to parse the cookie.parameters (
CookieParameters
) – Parameters for the cookie.
Methods Summary
dispatch
(request, call_next)Methods Documentation