Skip to content
Myr

Factor out the proxy selection code

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jason Grout · committed by Jason Grout · parent 2c87215 · Browse files · 2 files+13 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+13 added−13 removed

  • other:+13 added−13 removed

2 files+13 added−13 removed

modified:requests/adapters.py+5 added-13 removed
15 unmodified lines
16from .packages.urllib3.util import Timeout as TimeoutSauce17from .packages.urllib3.util.retry import Retry18from .compat import urlparse, basestring19from .utils import (DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers,20 prepend_scheme_if_needed, get_auth_from_url, urldefragauth)20 prepend_scheme_if_needed, get_auth_from_url, urldefragauth,21 select_proxy)22from .structures import CaseInsensitiveDict23from .packages.urllib3.exceptions import ConnectTimeoutError24from .packages.urllib3.exceptions import HTTPError as _HTTPError25from .packages.urllib3.exceptions import MaxRetryError
212 unmodified lines
238239 :param url: The URL to connect to.240 :param proxies: (optional) A Requests-style dictionary of proxies used on this request.241 """241 proxies = proxies or {}242 urlparts = urlparse(url.lower())243 proxy = proxies.get(urlparts.scheme+'://'+urlparts.hostname)244 if proxy is None:245 proxy = proxies.get(urlparts.scheme)242 proxy = select_proxy(url, proxies)243244 if proxy:245 proxy = prepend_scheme_if_needed(proxy, 'http')246 proxy_manager = self.proxy_manager_for(proxy)
26 unmodified lines
273274 :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.275 :param proxies: A dictionary of schemes to proxy URLs.276 """280 proxies = proxies or {}281 urlparts = urlparse(request.url.lower())282 proxy = proxies.get(urlparts.scheme+'://'+urlparts.hostname)283 if proxy is None:284 proxy = proxies.get(urlparts.scheme)285286 if proxy and urlparts.scheme != 'https':277 proxy = select_proxy(request.url, proxies)278 if proxy and not request.url.lower().startswith('https'):279 url = urldefragauth(request.url)280 else:281 url = request.path_url282
149 unmodified lines
modified:requests/utils.py+8 added
535 unmodified lines
536 return {}537 else:538 return getproxies()539540def select_proxy(url, proxies):541 """Select a proxy, if applicable."""542 proxies = proxies or {}543 urlparts = urlparse(url.lower())544 proxy = proxies.get(urlparts.scheme+'://'+urlparts.hostname)545 if proxy is None:546 proxy = proxies.get(urlparts.scheme)547 return proxy548549def default_user_agent(name="python-requests"):550 """Return a string representing the default user agent."""551 _implementation = platform.python_implementation()
165 unmodified lines