Asynchronous Middleware

A WSGI Middleware is a function or callable object similar to a WSGI application handlers with the only difference that it can return nothing (None).

Middleware can be used in conjunction with a WsgiHandler or any other handler which iterate through a list of middleware in a similar way (for example django wsgi handler).


An asynchronous WSGI middleware is a callble accepting a WSGI environ and start_response as the only input paramaters and it must returns an asynchronous iterator or nothing.

The two most important wsgi middleware in pulsar are:

  • the Router for serving dynamic web applications
  • the MediaRouter for serving static files

In addition, pulsar provides with the following four middlewares which don’t serve requests, instead they perform initialisation and sanity checks.

Clean path

pulsar.apps.wsgi.middleware.clean_path_middleware(environ, start_response=None)[source]

Clean url from double slashes and redirect if needed.


pulsar.apps.wsgi.middleware.authorization_middleware(environ, start_response=None)[source]

Parse the HTTP_AUTHORIZATION key in the environ.

If available, set the http.authorization key in environ with the result obtained from parse_authorization_header() function.

Wait for request body

pulsar.apps.wsgi.middleware.wait_for_body_middleware(environ, start_response=None)[source]

Use this middleware to wait for the full body.

This middleware wait for the full body to be received before letting other middleware to be processed.

Useful when using synchronous web-frameworks such as django.

Middleware in Executor


Use this middleware to run a synchronous middleware in the event loop executor.

Useful when using synchronous web-frameworks such as django.