You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
HTTPX supports setting up [HTTP proxies](https://en.wikipedia.org/wiki/Proxy_server#Web_proxy_servers) via the `proxies` parameter to be passed on client initialization or top-level API functions like `httpx.get(..., proxies=...)`.
<figcaption><em>Diagram of how a proxy works (source: Wikipedia). The left hand side "Internet" blob may be your HTTPX client requesting <code>example.com</code> through a proxy.</em></figcaption>
@@ -565,44 +563,34 @@ See documentation on [`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`](environment_vari
565
563
In general, the flow for making an HTTP request through a proxy is as follows:
566
564
567
565
1. The client connects to the proxy (initial connection request).
568
-
1. The proxy somehow transfers data to the server on your behalf.
566
+
2. The proxy transfers data to the server on your behalf.
569
567
570
568
How exactly step 2/ is performed depends on which of two proxying mechanisms is used:
571
569
572
570
***Forwarding**: the proxy makes the request for you, and sends back the response it obtained from the server.
573
-
***Tunneling**: the proxy establishes a TCP connection to the server on your behalf, and the client reuses this connection to send the request and receive the response. This is known as an [HTTP Tunnel](https://en.wikipedia.org/wiki/HTTP_tunnel). This mechanism is how you can access websites that use HTTPS from an HTTP proxy (the client "upgrades" the connection to HTTPS by performing the TLS handshake with the server over the TCP connection provided by the proxy).
571
+
***Tunnelling**: the proxy establishes a TCP connection to the server on your behalf, and the client reuses this connection to send the request and receive the response. This is known as an [HTTP Tunnel](https://en.wikipedia.org/wiki/HTTP_tunnel). This mechanism is how you can access websites that use HTTPS from an HTTP proxy (the client "upgrades" the connection to HTTPS by performing the TLS handshake with the server over the TCP connection provided by the proxy).
574
572
575
-
#### Default behavior
573
+
###Troubleshooting proxies
576
574
577
-
Given the technical definitions above, by default (and regardless of whether you're using an HTTP or HTTPS proxy), HTTPX will:
575
+
If you encounter issues when setting up proxies, please refer to our [Troubleshooting guide](troubleshooting.md#proxies).
578
576
579
-
* Use forwarding for HTTP requests.
580
-
* Use tunneling for HTTPS requests.
577
+
## SOCKS
581
578
582
-
This ensures that you can make HTTP and HTTPS requests in all cases (i.e. regardless of which type of proxy you're using).
579
+
In addition to HTTP proxies, `httpcore` also supports proxies using the SOCKS protocol.
580
+
This is an optional feature that requires an additional third-party library be installed before use.
583
581
584
-
#### Forcing the proxy mechanism
582
+
You can install SOCKS support using `pip`:
585
583
586
-
In most cases, the default behavior should work just fine as well as provide enough security.
584
+
```shell
585
+
$ pip install httpx[socks]
586
+
```
587
587
588
-
But if you know what you're doing and you want to force which mechanism to use, you can do so by passing an `httpx.Proxy()` instance, setting the `mode` to either `FORWARD_ONLY` or `TUNNEL_ONLY`. For example...
588
+
You can now configure a client to make requests via a proxy using the SOCKS protocol:
589
589
590
590
```python
591
-
# Route all requests through an HTTPS proxy, using tunneling only.
592
-
proxies = httpx.Proxy(
593
-
url="https://localhost:8030",
594
-
mode="TUNNEL_ONLY",
595
-
)
596
-
597
-
with httpx.Client(proxies=proxies) as client:
598
-
# This HTTP request will be tunneled instead of forwarded.
0 commit comments