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 bytes 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
environattribute as their only private data. Every other attribute is stored in theenvironitself at thepulsar.cachewsgi-extension key.-
cache¶ An attribute dictionary of pulsar-specific data stored in the
environat the wsgi-extension keypulsar.cache
-
connection¶ The
Connectionhandling the request
-
Wsgi Request¶
-
class
pulsar.apps.wsgi.wrappers.WsgiRequest(environ, app_handler=None, urlargs=None)[source]¶ An
EnvironMixinfor wsgi requests.-
content_types¶ List of content types this client supports as a
ContentAcceptobject.Obtained form the
Acceptrequest header.
-
charsets¶ List of charsets this client supports as a
CharsetAcceptobject.Obtained form the
Accept-Charsetrequest header.
-
encodings¶ List of encodings this client supports as
Acceptobject.Obtained form the
Accept-Charsetrequest header. Encodings in a HTTP term are compression encodings such as gzip. For charsets have a look atcharsetsattribute.
-
languages¶ List of languages this client accepts as
LanguageAcceptobject.Obtained form the
Accept-Languagerequest 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
Routerdoes.
-
cfg¶ The config container of the server
-
response¶ The
WsgiResponsefor this client request.
-
method¶ The request method (uppercase).
-
data_and_files(data=True, files=True, stream=None)[source]¶ Retrieve body data.
Returns a two-elements tuple of a
MultiValueDictcontaining data from the request body, and data from uploaded files.If the body data is not ready, return a
Futurewhich results in the tuple.The result is cached.
-
body_data()[source]¶ A
MultiValueDictcontaining 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, **query)[source]¶ Builds an absolute URI from
locationand variables available in this request.If no
locationis specified, the relative URI is built fromfull_path().
-
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
WsgiResponseis 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
SimpleCookiecontainer 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.
expirescan be a string in the correct format or adatetime.datetimeobject in UTC. Ifexpiresis a datetime object thenmax_agewill be calculated.
-