Implement per-host proxies

This change allows the proxy dict to be have entries of the form
{'<scheme>://<hostname>': '<proxy>'}.  Host-specific proxies will be used in
preference to the scheme-specific proxies (i.e., proxy dict entries with keys
like 'http' or 'https').

Fixes #2722
This commit is contained in:
Jason Grout
2015-08-20 21:59:57 +00:00
parent cef2589436
commit 48fe34447d
+2 -1
View File
@@ -239,7 +239,8 @@ class HTTPAdapter(BaseAdapter):
:param proxies: (optional) A Requests-style dictionary of proxies used on this request.
"""
proxies = proxies or {}
proxy = proxies.get(urlparse(url.lower()).scheme)
u = urlparse(url.lower())
proxy = proxies.get(u.scheme+'://'+u.hostname, proxies.get(u.scheme))
if proxy:
proxy = prepend_scheme_if_needed(proxy, 'http')