Skip to content
Access-Control-Allow-Origin etc middleware for WSGI
Find file
Latest commit ab07fb2 Jan 19, 2011 @ianb markup fix
Failed to load latest commit information.
wsgiaccesscontrol initial code Jan 19, 2011
.gitignore initial code Jan 19, 2011
README.rst markup fix Jan 19, 2011 readme, license Jan 19, 2011


WSGI Access-Control Middleware

This is a simple middleware for adding Access-Control-* headers to your application, allowing Cross-Origin Resource Sharing -- basically meaning that you can use XMLHttpRequest from one domain to access resources on another domain.

The middleware is located in wsgiaccesscontrol.accesscontrol.AccessControl.

Example of use

This is the code that we use to make the Firefox Sync web service available across origins (domains):

application = AccessControlMiddleware(
    application, allow_origin='*',
    allow_headers=('X-Authorization', 'Authorization',
                   'X-If-Modified-Since', 'X-If-Unmodified-Since',
    expose_headers=('X-Weave-Timestamp', 'X-Weave-Backoff',
                    'X-Weave-Alert', 'X-Weave-Records'))

Note that there is a little workaround for a Chrome bug that turns * into a dynamic Access-Control-Allow-Origin header (copying the Origin request header). A simple future feature is to allow a whitelist of origins (instead of just a single domain or wildcard), which also requires a dynamic Allow-Origin header (because the header is only allowed to include one value).

Something went wrong with that request. Please try again.