Response Middleware

Response middleware are callable objects which can be used in conjunction with pulsar WsgiHandler. They must return a WsgiResponse which can be the same as the one passed to the callable or a brand new one.

Interface

class pulsar.apps.wsgi.response.ResponseMiddleware[source]

Base class for response middlewares.

A response middleware is used by a WsgiHandler, it is a callable used to manipulate a WsgiResponse.

The focus of this class is the execute() method where the middleware logic is implemented.

available(environ, response)[source]

Check if this ResponseMiddleware can be applied to the response object.

Parameters:
Returns:

True or False.

execute(environ, response)[source]

Manipulate response, called only if the available() method returns True.

GZip Middleware

class pulsar.apps.wsgi.response.GZipMiddleware(min_length=200)[source]

A ResponseMiddleware for compressing content if the request allows gzip compression. It sets the Vary header accordingly.

The compression implementation is from http://jython.xhaus.com/http-compression-in-python-and-jython

AccessControl

class pulsar.apps.wsgi.response.AccessControl(origin='*', methods=None)[source]

A response middleware which add the Access-Control-Allow-Origin response header.