bocadillo.middleware

Middleware

Middleware(self, inner:bocadillo.app_types.ASGIApp)

Base class for HTTP middleware classes.

Parameters

  • inner (callable): the inner middleware that this middleware wraps.

before_dispatch

Middleware.before_dispatch(self, req:bocadillo.request.Request, res:bocadillo.response.Response) -> Union[bocadillo.response.Response, NoneType]

Perform processing before a request is dispatched.

If the Response object is returned, it will be sent and no further processing will be performed.

after_dispatch

Middleware.after_dispatch(self, req:bocadillo.request.Request, res:bocadillo.response.Response) -> None

Perform processing after a request has been dispatched.

ExceptionMiddleware

ExceptionMiddleware(self, app:bocadillo.app_types.ASGIApp, handlers:Dict[Type[BaseException], Callable[[bocadillo.request.Request, bocadillo.response.Response, BaseException], Awaitable[NoneType]]]) -> None

Handle exceptions that occur while processing requests.

ServerErrorMiddleware

ServerErrorMiddleware(self, app:bocadillo.app_types.ASGIApp, handler:Callable[[bocadillo.request.Request, bocadillo.response.Response, BaseException], Awaitable[NoneType]]) -> None

Return a 500 error response when an unhandled exception occurs.

RequestResponseMiddleware

RequestResponseMiddleware(self, app)

Make req and res available to HTTP routes and middleware.

Note: this is mostly an implementation detail.