Link to ASGI docs (#577)

This commit is contained in:
Tom Christie 2019-11-30 18:38:27 +00:00 committed by GitHub
parent 248aa580a1
commit 7d45db068b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -75,7 +75,7 @@ For a list of all available client-level parameters, see the [`Client` API refer
## Calling into Python Web Apps
You can configure an `httpx` client to call directly into a Python web
application using either the ASGI protocol.
application using the ASGI protocol.
This is particularly useful for two main use-cases:
@ -107,22 +107,25 @@ We can make requests directly against the application, like so:
... assert r.text == "Hello World!"
```
For some more complex cases you might need to customize the WSGI or ASGI
dispatch. This allows you to:
For some more complex cases you might need to customise the ASGI dispatch. This allows you to:
* Inspect 500 error responses rather than raise exceptions by setting `raise_app_exceptions=False`.
* Mount the WSGI or ASGI application at a subpath by setting `root_path`.
* Mount the ASGI application at a subpath by setting `root_path`.
* Use a given client address for requests by setting `client`.
For example:
```python
# Instantiate a client that makes WSGI requests with a client IP of "1.2.3.4".
dispatch = httpx.dispatch.ASGIDispatch(app=app, remote_addr="1.2.3.4")
# Instantiate a client that makes ASGI requests with a client IP of "1.2.3.4",
# on port 123.
dispatch = httpx.dispatch.ASGIDispatch(app=app, client=("1.2.3.4", 123))
async with httpx.Client(dispatch=dispatch) as client:
...
```
See [the ASGI documentation](https://asgi.readthedocs.io/en/latest/specs/www.html#connection-scope) for more details on the `client` and `root_path`
keys.
## Build Request
You can use `Client.build_request()` to build a request and