Drop `raise_app_exceptions` Client argument. (#238)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Drop `raise_app_exceptions` keyword argument * Improve docstrings for WSGIDispatch and ASGIDispatch * Add docs for fine grained WSGI/ASGI control
authored by Tom Christie · committed by GitHub · parent a960a2a · Browse files · 4 files·+36 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+36 added−7 removed
- other:+36 added−7 removed
Provenance
- Commit
ef9fc0f- Tree
a8d6b2e- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
a960a2a
4 files changed+36 added−7 removed
modified:docs/advanced.md+15 added
40 unmodified lines414243444546474849505152535455565758596061626323 unmodified lines40 unmodified linesassert r.status_code == 200assert r.text == "Hello World!"```
For some more complex cases you might need to customize the WSGI or ASGIdispatch. 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 `script_name` (WSGI) or `root_path` (ASGI).* Use a given the client address for requests, by setting `remote_addr` (WSGI) or `client` (ASGI).
For example:
```python# Instantiate a client that makes WSGI requests with a client IP of "1.2.3.4".dispatch = httpx.WSGIDispatch(app=app, remote_addr="1.2.3.4")client = httpx.Client(dispatch=dispatch)```
## .netrc Support
HTTPX supports .netrc file. In `trust_env=True` cases, if auth parameter isnot defined, HTTPX tries to add auth into request's header from .netrc file.23 unmodified linesmodified:httpx/dispatch/asgi.py+9 added
27 unmodified lines28 root_path="/submount",29 client=("1.2.3.4", 123)30 )31 client = httpx.Client(dispatch=dispatch)32+33+ Arguments:34+35+ * `app` - The ASGI application.36+ * `raise_app_exceptions` - Boolean indicating if exceptions in the application37+ should be raised. Default to `True`. Can be set to `False` for use cases38+ such as testing the content of a client 500 response.39+ * `root_path` - The root path on which the ASGI application should be mounted.40+ * `client` - A two-tuple indicating the client IP and port of incoming requests.41 ```42 """43 44 def __init__(152 unmodified linesmodified:httpx/dispatch/wsgi.py+10 added
27 unmodified lines28 script_name="/submount",29 remote_addr="1.2.3.4"30 )31 client = httpx.Client(dispatch=dispatch)32+33+34+ Arguments:35+36+ * `app` - The ASGI application.37+ * `raise_app_exceptions` - Boolean indicating if exceptions in the application38+ should be raised. Default to `True`. Can be set to `False` for use cases39+ such as testing the content of a client 500 response.40+ * `script_name` - The root path on which the ASGI application should be mounted.41+ * `remote_addr` - A string indicating the client IP of incoming requests.42 ```43 """44 45 def __init__(119 unmodified linesmodified:httpx/client.py+2 added-7 removed
61 unmodified lines62 max_redirects: int = DEFAULT_MAX_REDIRECTS,63 base_url: URLTypes = None,64 dispatch: typing.Union[AsyncDispatcher, Dispatcher] = None,65 app: typing.Callable = None,66- raise_app_exceptions: bool = True,66 backend: ConcurrencyBackend = None,67 trust_env: bool = None,68 ):69 if backend is None:4 unmodified lines74 if app is not None:75 param_count = len(inspect.signature(app).parameters)76 assert param_count in (2, 3)77 if param_count == 2:79- dispatch = WSGIDispatch(80- app=app, raise_app_exceptions=raise_app_exceptions81- )78+ dispatch = WSGIDispatch(app=app)79 else:83- dispatch = ASGIDispatch(84- app=app, raise_app_exceptions=raise_app_exceptions85- )80+ dispatch = ASGIDispatch(app=app)81 82 if dispatch is None:83 async_dispatch: AsyncDispatcher = ConnectionPool(84 verify=verify,899 unmodified lines