class documentation

class WSGITransport(BaseTransport):

View In Hierarchy

A custom transport that handles sending requests directly to an WSGI app. The simplest way to use this functionality is to use the app argument.

` client = httpx.Client(app=app) `

Alternatively, you can setup the transport instance explicitly. This allows you to include any additional configuration arguments specific to the WSGITransport class:

``` transport = httpx.WSGITransport(

app=app, script_name="/submount", remote_addr="1.2.3.4"

) client = httpx.Client(transport=transport) ```

Arguments:

  • app - The ASGI application.
  • raise_app_exceptions - Boolean indicating if exceptions in the application
    should be raised. Default to True. Can be set to False for use cases such as testing the content of a client 500 response.
  • script_name - The root path on which the WSGI application should be mounted.
  • remote_addr - A string indicating the client IP of incoming requests.

```

Method __init__ Undocumented
Method handle​_request Send a single HTTP request and return a response.
Instance Variable app Undocumented
Instance Variable raise​_app​_exceptions Undocumented
Instance Variable remote​_addr Undocumented
Instance Variable script​_name Undocumented
Instance Variable wsgi​_errors Undocumented

Inherited from BaseTransport:

Method __enter__ Undocumented
Method __exit__ Undocumented
Method close Undocumented
def __init__(self, app, raise_app_exceptions=True, script_name='', remote_addr='127.0.0.1', wsgi_errors=None):

Undocumented

Parameters
app:typing.CallableUndocumented
raise​_app​_exceptions:boolUndocumented
script​_name:strUndocumented
remote​_addr:strUndocumented
wsgi​_errors:typing.Optional[typing.TextIO]Undocumented
def handle_request(self, request):

Send a single HTTP request and return a response.

At this layer of API we're simply using plain primitives. No Request or Response models, no fancy URL or Header handling. This strict point of cut-off provides a clear design separation between the HTTPX API, and the low-level network handling.

Developers shouldn't typically ever need to call into this API directly, since the Client class provides all the higher level user-facing API niceties.

In order to properly release any network resources, the response stream should either be consumed immediately, with a call to stream.read(), or else the handle_request call should be followed with a try/finally block to ensuring the stream is always closed.

Example usage:

with httpx.HTTPTransport() as transport:
status_code, headers, stream, extensions = transport.handle_request(
method=b'GET', url=(b'https', b'www.example.com', 443, b'/'), headers=[(b'Host', b'www.example.com')], stream=[], extensions={}

) body = stream.read() print(status_code, headers, body)

Arguments:

method: The request method as bytes. Eg. b'GET'. url: The components of the request URL, as a tuple of (scheme, host, port, target).

The target will usually be the URL path, but also allows for alternative formulations, such as proxy requests which include the complete URL in the target portion of the HTTP request, or for "OPTIONS *" requests, which cannot be expressed in a URL string.

headers: The request headers as a list of byte pairs. stream: The request body as a bytes iterator. extensions: An open ended dictionary, including optional extensions to the

core request/response API. Keys may include:
timeout: A dictionary of str:Optional[float] timeout values.
May include values for 'connect', 'read', 'write', or 'pool'.

Returns a tuple of:

status_code: The response status code as an integer. Should be in the range 1xx-5xx. headers: The response headers as a list of byte pairs. stream: The response body as a bytes iterator. extensions: An open ended dictionary, including optional extensions to the

core request/response API. Keys are plain strings, and may include:
reason_phrase: The reason-phrase of the HTTP response, as bytes. Eg b'OK'.
HTTP/2 onwards does not include a reason phrase on the wire. When no key is included, a default based on the status code may be used. An empty-string reason phrase should not be substituted for a default, as it indicates the server left the portion blank eg. the leading response bytes were b"HTTP/1.1 200 <CRLF>".
http_version: The HTTP version, as bytes. Eg. b"HTTP/1.1".
When no http_version key is included, HTTP/1.1 may be assumed.
Parameters
request:RequestUndocumented
Returns
ResponseUndocumented
app =

Undocumented

raise_app_exceptions =

Undocumented

remote_addr =

Undocumented

script_name =

Undocumented

wsgi_errors =

Undocumented