drakken.middleware module

Middleware module.

Middleware acts as a middleman between the web server and your app. The middleware wraps around the app, allowing it to modify a request before your app receives it or modify a response after your app processes it. An app can have several middleware, all wrapped around the app like the layers of an onion.

class drakken.middleware.Middleware(app)

Bases: object

Parent class.

To create a middleware, subclass this class and override process_request or process_response.

Parameters:

app – The drakken.core.Drakken object this middleware handles.

add(middleware)

Wrap another middleware around the app.

Allows you to daisy-chain multiple middleware to an app.

Parameters:

middleware (Middleware) – Middleware object.

handle_request(request)

Execute the handler for this request.

Parameters:

request (Request) – Request object.

process_request(request)

Child class overrides this method.

process_response(request, response)

Child class overrides this method.