Skip to content
Myr

Refine docs phrasing on proxy routing (#1124)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Florimond Manca · committed by GitHub · parent 70cdd95 · Browse files · 1 file+6 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+6 added−15 removed

  • other:+6 added−15 removed

1 file+6 added−15 removed

modified:docs/advanced.md+6 added-15 removed
278 unmodified lines
279with httpx.Client(proxies="http://localhost:8030") as client:280 ...281```282283To route HTTP and HTTPS requests to 2 different proxies, respectively located at `http://localhost:8030`, and `http://localhost:8031`, pass a `dict` of proxy URLs:283For more advanced use cases, pass a proxies `dict`. For example, to route HTTP and HTTPS requests to 2 different proxies, respectively located at `http://localhost:8030`, and `http://localhost:8031`, pass a `dict` of proxy URLs:284285```python286proxies = {287 "http": "http://localhost:8030",
25 unmodified lines
313```314315### Routing316317HTTPX supports configuring which requests go through a given proxy and which don't based on the requested **scheme**, **domain**, **port**, or a combination of these.317HTTPX provides fine-grained controls for deciding which requests should go through a proxy, and which shouldn't. This process is known as proxy routing.318319The `proxies` dictionary maps URL patterns ("proxy keys") to proxy URLs. HTTPX matches requested URLs against proxy keys to decide which proxy should be used, if any. Matching is done from most specific proxy keys (e.g. `https://<domain>:<port>`) to least specific ones (e.g. `https`).320321HTTPX supports routing proxies based on **scheme**, **domain**, **port**, or a combination of these.322323#### Wildcard routing324325Route everything through a proxy...326
2 unmodified lines
329 "all": "http://localhost:8030",330}331```332329(This is equivalent to `Client(..., proxies="http://localhost:8030")`.)330333#### Scheme routing334335Route HTTP requests through one proxy, and HTTPS requests through another...336
94 unmodified lines
431HTTP proxying can also be configured through environment variables, although with less fine-grained control.432433See documentation on [`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`](/environment_variables/#http_proxy-https_proxy-all_proxy) for more information.434433#### Routing algorithm overview434435For reference, the proxy routing algorithm used by HTTPX is roughly as follows...4364371. Sort proxy keys in decreasing order of specificity. (For example, a proxy on `all://example.com` comes before a proxy on `all`.) _This is done on client instanciation._4381. When making a request, go through sorted proxies, looking for a matching key...439 1. If a key matches...440 1. ...But the value is `None`, no proxy is used.441 1. Otherwise, the associated proxy is used.442 1. If no key matched, no proxy is used.443435### Proxy mechanisms436437!!! note438 This section describes **advanced** proxy concepts and functionality.
422 unmodified lines