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
ResponseMiddlewarecan be applied to theresponseobject.Parameters: - environ – a WSGI environ dictionary.
- response – a
pulsar.apps.wsgi.wrappers.WsgiResponse
Returns: TrueorFalse.
-
execute(environ, response)[source]¶ Manipulate response, called only if the
available()method returnsTrue.
-
GZip Middleware¶
-
class
pulsar.apps.wsgi.response.GZipMiddleware(min_length=200)[source]¶ A
ResponseMiddlewarefor 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