@@ -7,7 +7,8 @@ Sending requests via a proxy is very similar to sending requests using a standar
7
7
``` python
8
8
import httpcore
9
9
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)
11
12
r = proxy.request(" GET" , " https://www.example.com/" )
12
13
13
14
print (r)
@@ -31,10 +32,11 @@ Proxy authentication can be included in the initial configuration:
31
32
import httpcore
32
33
33
34
# 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>" )
37
38
)
39
+ pool = httpcore.ConnectionPool(proxy = proxy)
38
40
```
39
41
40
42
Custom headers can also be included:
@@ -45,10 +47,11 @@ import base64
45
47
46
48
# Construct and include a `Proxy-Authorization` header.
47
49
auth = 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}
51
53
)
54
+ pool = httpcore.ConnectionPool(proxy = proxy)
52
55
```
53
56
54
57
## Proxy SSL
@@ -58,10 +61,10 @@ The `httpcore` package also supports HTTPS proxies for http and https destinatio
58
61
HTTPS proxies can be used in the same way that HTTP proxies are.
59
62
60
63
``` python
61
- proxy = httpcore.HTTPProxy( proxy_url = " https://127.0.0.1:8080/" )
64
+ proxy = httpcore.Proxy( url = " https://127.0.0.1:8080/" )
62
65
```
63
66
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.
65
68
66
69
``` python
67
70
import ssl
@@ -70,11 +73,13 @@ import httpcore
70
73
proxy_ssl_context = ssl.create_default_context()
71
74
proxy_ssl_context.check_hostname = False
72
75
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)
74
81
```
75
82
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
-
78
83
## HTTP Versions
79
84
80
85
If 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:
91
96
import httpcore
92
97
93
98
# 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/" )
96
102
```
97
103
98
104
Authentication via SOCKS is also supported:
99
105
100
106
``` python
101
107
import httpcore
102
108
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>" ),
106
112
)
107
- r = proxy.request(" GET" , " https://www.example.com/" )
113
+ pool = httpcore.ConnectionPool(proxy = proxy)
114
+ r = pool.request(" GET" , " https://www.example.com/" )
108
115
```
109
116
110
117
---
111
118
112
119
# Reference
113
120
114
- ## ` httpcore.HTTPProxy `
121
+ ## ` httpcore.Proxy `
115
122
116
- ::: httpcore.HTTPProxy
123
+ ::: httpcore.Proxy
117
124
handler: python
118
125
rendering:
119
126
show_source: False
0 commit comments