Middleware

class rivr.middleware.Middleware(**kwargs)
classmethod wrap(view, **kwargs)

The wrap method allows you to wrap a view calling the middleware’s process_request and process_response before and after the view.

If the view raises an exception, the process_exception method will be called.

Example:

view = Middleware.wrap(view)
response = view(request)
process_request(self, request)

This method is called before the view on each request. This method should either return a response or None. If it returns a response, then the middleware will not call the view. If it returns None, then we will call the view.

process_response(self, request, response)

This method will take the response, either from process_request or the view. This method will always be called for each request unless there is an exception.

This method must return a response, this can either be the response passed to it, or a completely new response.

class rivr.middleware.MiddlewareController(*middleware)

The middleware controller allows you to wrap a view in multiple middleware.

Example usage:

view = MiddlewareController.wrap(view,
    FirstMiddleware(),
    SecondMiddleware()
)

response = view(request)