Documentation for pulsar 0.9.2. For development docs, go here.
This section introduces two 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.
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.
cache
¶An attribute dictionary of
pulsar-specific data stored in the environ
at
the wsgi-extension key pulsar.cache
connection
¶The Connection
handling the request
pulsar.apps.wsgi.wrappers.
WsgiRequest
(environ, app_handler=None, urlargs=None)[source]¶An EnvironMixin
for wsgi requests.
content_types
¶List of content types this client supports as a
ContentAccept
object.
Obtained form the Accept
request header.
charsets
¶List of charsets this client supports as a
CharsetAccept
object.
Obtained form the Accept-Charset
request header.
encodings
¶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.
languages
¶List of languages this client accepts as
LanguageAccept
object.
Obtained form the Accept-Language
request header.
Container of request cookies
app_handler
¶The WSGI application handling this request.
The WSGI handler is responsible for setting this value in the
same way as the Router
does.
cfg
¶The config container of the server
ipaddress
¶internet protocol address of the client
response
¶The WsgiResponse
for this client request.
method
¶The request method (uppercase).
data_and_files
(data=True, files=True)[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.
body_data
()[source]¶A MultiValueDict
containing data from the request body.
html_document
¶Return a cached instance of HtmlDocument
.
get_host
(use_x_forwarded=True)[source]¶Returns the HTTP host using the environment or request headers.
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()
.
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.
status_code
¶Integer indicating the HTTP status, (i.e. 200)
response
¶String indicating the HTTP status (i.e. ‘OK’)
status
¶String indicating the HTTP status code and response (i.e. ‘200 OK’)
content_type
¶The content type of this response. Can be None
.
environ
¶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.
is_streamed
¶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.
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.