WSGI Wrappers

This section introduces classes used by pulsar wsgi application to pass a request/response state during an HTTP request.

The WsgiRequest is a thin wrapper around a WSGI environ dictionary. It contains only the environ as its private data. The WsgiResponse, which is available in the WsgiRequest.response attribute, is an iterable over bytestring with several utility methods for manipulating headers and asynchronous content.

Environ Mixin

class pulsar.apps.wsgi.wrappers.EnvironMixin(environ, name=None)[source]

A wrapper around a WSGI environ.

Instances of this class have the environ attribute as their only private data. Every other attribute is stored in the environ itself at the pulsar.cache wsgi-extension key.


WSGI environ dictionary


An attribute dictionary of pulsar-specific data stored in the environ at the wsgi-extension key pulsar.cache


The Connection handling the request

get(key, default=None)[source]

Shortcut to the environ get method.

Wsgi Request

class pulsar.apps.wsgi.wrappers.WsgiRequest(environ, app_handler=None, urlargs=None)[source]

An EnvironMixin for wsgi requests.


List of content types this client supports as a ContentAccept object.

Obtained form the Accept request header.


List of charsets this client supports as a CharsetAccept object.

Obtained form the Accept-Charset request header.


List of encodings this client supports as Accept object.

Obtained form the Accept-Charset request header. Encodings in a HTTP term are compression encodings such as gzip. For charsets have a look at charsets attribute.


List of languages this client accepts as LanguageAccept object.

Obtained form the Accept-Language request header.


Container of request cookies


The WSGI application handling this request.

The WSGI handler is responsible for setting this value in the same way as the Router does.


Dictionary of url parameters obtained when matching a router with this request path.


The config container of the server


The WsgiResponse for this client request.


True if this is an AJAX request


True if this request is via a TLS connection


Shortcut to the environ PATH_INFO value.


The request method (uppercase).

data_and_files(data=True, files=True, stream=None)[source]

Retrieve body data.

Returns a two-elements tuple of a MultiValueDict containing data from the request body, and data from uploaded files.

If the body data is not ready, return a Future which results in the tuple.

The result is cached.


A MultiValueDict containing data from the request body.


A (cached) dictionary containing data from the QUERY_STRING in environ.


Return a cached instance of HtmlDocument.


Returns the HTTP host using the environment or request headers.


Obtain the client IP address

full_path(*args, **query)[source]

Return a full path

absolute_uri(location=None, scheme=None)[source]

Builds an absolute URI from location and variables available in this request.

If no location is specified, the relative URI is built from full_path().

redirect(path, **kw)[source]

Redirect to a different path


Evaluate the content type for the response to a client request.

The method uses the response_content_types parameter of accepted content types and the content types accepted by the client request and figures out the best match.

Wsgi Response

class pulsar.apps.wsgi.wrappers.WsgiResponse(status=None, content=None, response_headers=None, content_type=None, encoding=None, environ=None, can_store_cookies=True)[source]

A WSGI response.

Instances are callable using the standard WSGI call and, importantly, iterable:

response = WsgiResponse(200)

A WsgiResponse is an iterable over bytes to send back to the requesting client.


Integer indicating the HTTP status, (i.e. 200)


String indicating the HTTP status (i.e. ‘OK’)


String indicating the HTTP status code and response (i.e. ‘200 OK’)


The content type of this response. Can be None.


The Headers container for this response.


The dictionary of WSGI environment if passed to the constructor.


A python SimpleCookie container of cookies included in the request as well as cookies set during the response.


Check if the response is streamed.

A streamed response is an iterable with no length information. In this case streamed means that there is no information about the number of iterations.

This is usually True if a generator is passed to the response object.


Close this response, required by WSGI

Sets a cookie.

expires can be a string in the correct format or a datetime.datetime object in UTC. If expires is a datetime object then max_age will be calculated.


The list of headers for this response

Wsgi File Wrapper

class pulsar.apps.wsgi.wrappers.FileWrapper(file, block=None)[source]

WSGI File wrapper class.

Available directly from the wsgi.file_wrapper key in the WSGI environ dictionary. Alternatively one can use the file_response() high level function for serving local files.