Add `proxies` parameter to top-level API functions (#1198)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Add `proxies` parameter to top-level API functions * Fix typo
authored by Joe · committed by GitHub · parent 25507ac · Browse files · 4 files·+24 added−4 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+24 added−4 removed
- other:+24 added−4 removed
Provenance
- Commit
84ca201- Tree
c3716a1- Author
Joe <nigelchiang@outlook.com>- Committer
GitHub <noreply@github.com>- Parent
25507ac
4 files changed+24 added−4 removed
modified:docs/advanced.md+1 added-1 removed
260 unmodified lines261 ```262 263 ## HTTP Proxying264 265-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.265+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=...)`.266 267 _Note: SOCKS proxies are not supported yet._268 269 <div align="center">631 unmodified linesmodified:docs/compatibility.md+2 added
40 unmodified lines4142434445464748495035 unmodified lines40 unmodified linesThis is different to the `requests` usage of `proxies={"http": ..., "https": ...}`.
This change is for better consistency with more complex mappings, that might also include domain names, such as `proxies={"all://": ..., "all://www.example.com": None}` which maps all requests onto a proxy, except for requests to "www.example.com" which have an explicit exclusion.
Also note that `requests.Session.request(...)` allows a `proxies=...` parameter, whereas `httpx.Client.request(...)` does not.
## SSL configuration
When using a `Client` instance, the `trust_env`, `verify`, and `cert` arguments should always be passed on client instantiation, rather than passed to the request method.
35 unmodified linesmodified:httpx/_api.py+20 added-2 removed
6 unmodified lines7 AuthTypes,8 CertTypes,9 CookieTypes,10 HeaderTypes,11+ ProxiesTypes,12 QueryParamTypes,13 RequestData,14 RequestFiles,15 TimeoutTypes,12 unmodified lines28 json: typing.Any = None,29 headers: HeaderTypes = None,30 cookies: CookieTypes = None,31 auth: AuthTypes = None,32+ proxies: ProxiesTypes = None,33 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,34 allow_redirects: bool = True,35 verify: VerifyTypes = True,36 cert: CertTypes = None,20 unmodified lines57 * **cookies** - *(optional)* Dictionary of Cookie items to include in the58 request.59 * **auth** - *(optional)* An authentication class to use when sending the60 request.61+ * **proxies** - *(optional)* A dictionary mapping proxy keys to proxy URLs.62 * **timeout** - *(optional)* The timeout configuration to use when sending63 the request.64 * **allow_redirects** - *(optional)* Enables or disables HTTP redirects.65 * **verify** - *(optional)* SSL certificates (a.k.a CA bundle) used to17 unmodified lines83 <Response [200 OK]>84 ```85 """86 with Client(84- cert=cert, verify=verify, timeout=timeout, trust_env=trust_env,87+ proxies=proxies, cert=cert, verify=verify, timeout=timeout, trust_env=trust_env,88 ) as client:89 return client.request(90 method=method,91 url=url,18 unmodified lines110 json: typing.Any = None,111 headers: HeaderTypes = None,112 cookies: CookieTypes = None,113 auth: AuthTypes = None,114+ proxies: ProxiesTypes = None,115 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,116 allow_redirects: bool = True,117 verify: VerifyTypes = True,118 cert: CertTypes = None,119 trust_env: bool = True,120 ) -> StreamContextManager:117- client = Client(cert=cert, verify=verify, trust_env=trust_env)121+ client = Client(proxies=proxies, cert=cert, verify=verify, trust_env=trust_env)122 request = Request(123 method=method,124 url=url,125 params=params,19 unmodified lines145 params: QueryParamTypes = None,146 headers: HeaderTypes = None,147 cookies: CookieTypes = None,148 auth: AuthTypes = None,149+ proxies: ProxiesTypes = None,150 allow_redirects: bool = True,151 cert: CertTypes = None,152 verify: VerifyTypes = True,153 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,13 unmodified lines167 params=params,168 headers=headers,169 cookies=cookies,170 auth=auth,171+ proxies=proxies,172 allow_redirects=allow_redirects,173 cert=cert,174 verify=verify,175 timeout=timeout,7 unmodified lines183 params: QueryParamTypes = None,184 headers: HeaderTypes = None,185 cookies: CookieTypes = None,186 auth: AuthTypes = None,187+ proxies: ProxiesTypes = None,188 allow_redirects: bool = True,189 cert: CertTypes = None,190 verify: VerifyTypes = True,191 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,13 unmodified lines205 params=params,206 headers=headers,207 cookies=cookies,208 auth=auth,209+ proxies=proxies,210 allow_redirects=allow_redirects,211 cert=cert,212 verify=verify,213 timeout=timeout,7 unmodified lines221 params: QueryParamTypes = None,222 headers: HeaderTypes = None,223 cookies: CookieTypes = None,224 auth: AuthTypes = None,225+ proxies: ProxiesTypes = None,226 allow_redirects: bool = True,227 cert: CertTypes = None,228 verify: VerifyTypes = True,229 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,15 unmodified lines245 params=params,246 headers=headers,247 cookies=cookies,248 auth=auth,249+ proxies=proxies,250 allow_redirects=allow_redirects,251 cert=cert,252 verify=verify,253 timeout=timeout,10 unmodified lines264 params: QueryParamTypes = None,265 headers: HeaderTypes = None,266 cookies: CookieTypes = None,267 auth: AuthTypes = None,268+ proxies: ProxiesTypes = None,269 allow_redirects: bool = True,270 cert: CertTypes = None,271 verify: VerifyTypes = True,272 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,13 unmodified lines286 params=params,287 headers=headers,288 cookies=cookies,289 auth=auth,290+ proxies=proxies,291 allow_redirects=allow_redirects,292 cert=cert,293 verify=verify,294 timeout=timeout,10 unmodified lines305 params: QueryParamTypes = None,306 headers: HeaderTypes = None,307 cookies: CookieTypes = None,308 auth: AuthTypes = None,309+ proxies: ProxiesTypes = None,310 allow_redirects: bool = True,311 cert: CertTypes = None,312 verify: VerifyTypes = True,313 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,13 unmodified lines327 params=params,328 headers=headers,329 cookies=cookies,330 auth=auth,331+ proxies=proxies,332 allow_redirects=allow_redirects,333 cert=cert,334 verify=verify,335 timeout=timeout,10 unmodified lines346 params: QueryParamTypes = None,347 headers: HeaderTypes = None,348 cookies: CookieTypes = None,349 auth: AuthTypes = None,350+ proxies: ProxiesTypes = None,351 allow_redirects: bool = True,352 cert: CertTypes = None,353 verify: VerifyTypes = True,354 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,13 unmodified lines368 params=params,369 headers=headers,370 cookies=cookies,371 auth=auth,372+ proxies=proxies,373 allow_redirects=allow_redirects,374 cert=cert,375 verify=verify,376 timeout=timeout,7 unmodified lines384 params: QueryParamTypes = None,385 headers: HeaderTypes = None,386 cookies: CookieTypes = None,387 auth: AuthTypes = None,388+ proxies: ProxiesTypes = None,389 allow_redirects: bool = True,390 cert: CertTypes = None,391 verify: VerifyTypes = True,392 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,13 unmodified lines406 params=params,407 headers=headers,408 cookies=cookies,409 auth=auth,410+ proxies=proxies,411 allow_redirects=allow_redirects,412 cert=cert,413 verify=verify,414 timeout=timeout,2 unmodified linesmodified:httpx/_client.py+1 added-1 removed
465 unmodified lines466 * **cert** - *(optional)* An SSL certificate used by the requested host467 to authenticate the client. Either a path to an SSL certificate file, or468 two-tuple of (certificate file, key file), or a three-tuple of (certificate469 file, key file, password).470- * **proxies** - *(optional)* A dictionary mapping HTTP protocols to proxy470+ * **proxies** - *(optional)* A dictionary mapping proxy keys to proxy471 URLs.472 * **timeout** - *(optional)* The timeout configuration to use when sending473 requests.474 * **limits** - *(optional)* The limits configuration to use.1227 unmodified lines