@@ -7,7 +7,8 @@ Sending requests via a proxy is very similar to sending requests using a standar
77``` python
88import httpcore
99
10- proxy = httpcore.HTTPProxy(proxy_url = " http://127.0.0.1:8080/" )
10+ proxy = httpcore.Proxy(" http://127.0.0.1:8080/" )
11+ pool = httpcore.ConnectionPool(proxy = proxy)
1112r = proxy.request(" GET" , " https://www.example.com/" )
1213
1314print (r)
@@ -31,10 +32,11 @@ Proxy authentication can be included in the initial configuration:
3132import httpcore
3233
3334# A `Proxy-Authorization` header will be included on the initial proxy connection.
34- proxy = httpcore.HTTPProxy (
35- proxy_url = " http://127.0.0.1:8080/" ,
36- proxy_auth = (" <username>" , " <password>" )
35+ proxy = httpcore.Proxy (
36+ url = " http://127.0.0.1:8080/" ,
37+ auth = (" <username>" , " <password>" )
3738)
39+ pool = httpcore.ConnectionPool(proxy = proxy)
3840```
3941
4042Custom headers can also be included:
@@ -45,10 +47,11 @@ import base64
4547
4648# Construct and include a `Proxy-Authorization` header.
4749auth = base64.b64encode(b " <username>:<password>" )
48- proxy = httpcore.HTTPProxy (
49- proxy_url = " http://127.0.0.1:8080/" ,
50- proxy_headers = {" Proxy-Authorization" : b " Basic " + auth}
50+ proxy = httpcore.Proxy (
51+ url = " http://127.0.0.1:8080/" ,
52+ headers = {" Proxy-Authorization" : b " Basic " + auth}
5153)
54+ pool = httpcore.ConnectionPool(proxy = proxy)
5255```
5356
5457## Proxy SSL
@@ -58,10 +61,10 @@ The `httpcore` package also supports HTTPS proxies for http and https destinatio
5861HTTPS proxies can be used in the same way that HTTP proxies are.
5962
6063``` python
61- proxy = httpcore.HTTPProxy( proxy_url = " https://127.0.0.1:8080/" )
64+ proxy = httpcore.Proxy( url = " https://127.0.0.1:8080/" )
6265```
6366
64- Also, when using HTTPS proxies, you may need to configure the SSL context, which you can do with the ` proxy_ssl_context ` argument.
67+ Also, when using HTTPS proxies, you may need to configure the SSL context, which you can do with the ` ssl_context ` argument.
6568
6669``` python
6770import ssl
@@ -70,11 +73,13 @@ import httpcore
7073proxy_ssl_context = ssl.create_default_context()
7174proxy_ssl_context.check_hostname = False
7275
73- proxy = httpcore.HTTPProxy(' https://127.0.0.1:8080/' , proxy_ssl_context = proxy_ssl_context)
76+ proxy = httpcore.Proxy(
77+ url = ' https://127.0.0.1:8080/' ,
78+ ssl_context = proxy_ssl_context
79+ )
80+ pool = httpcore.ConnectionPool(proxy = proxy)
7481```
7582
76- It is important to note that the ` ssl_context ` argument is always used for the remote connection, and the ` proxy_ssl_context ` argument is always used for the proxy connection.
77-
7883## HTTP Versions
7984
8085If you use proxies, keep in mind that the ` httpcore ` package only supports proxies to HTTP/1.1 servers.
@@ -91,29 +96,31 @@ The `SOCKSProxy` class should be using instead of a standard connection pool:
9196import httpcore
9297
9398# Note that the SOCKS port is 1080.
94- proxy = httpcore.SOCKSProxy(proxy_url = " socks5://127.0.0.1:1080/" )
95- r = proxy.request(" GET" , " https://www.example.com/" )
99+ proxy = httpcore.Proxy(url = " socks5://127.0.0.1:1080/" )
100+ pool = httpcore.ConnectionPool(proxy = proxy)
101+ r = pool.request(" GET" , " https://www.example.com/" )
96102```
97103
98104Authentication via SOCKS is also supported:
99105
100106``` python
101107import httpcore
102108
103- proxy = httpcore.SOCKSProxy (
104- proxy_url = " socks5://127.0.0.1:8080 /" ,
105- proxy_auth = (" <username>" , " <password>" )
109+ proxy = httpcore.Proxy (
110+ url = " socks5://127.0.0.1:1080 /" ,
111+ auth = (" <username>" , " <password>" ),
106112)
107- r = proxy.request(" GET" , " https://www.example.com/" )
113+ pool = httpcore.ConnectionPool(proxy = proxy)
114+ r = pool.request(" GET" , " https://www.example.com/" )
108115```
109116
110117---
111118
112119# Reference
113120
114- ## ` httpcore.HTTPProxy `
121+ ## ` httpcore.Proxy `
115122
116- ::: httpcore.HTTPProxy
123+ ::: httpcore.Proxy
117124 handler: python
118125 rendering:
119126 show_source: False
0 commit comments