Skip to content
Myr

Proxy urls should have explicit schemes.

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

authored by Cory Benfield · committed by Cory Benfield · parent 9473f15 · Browse files · 2 files+13 added−17 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−17 removed

  • other:+13 added−17 removed

2 files+13 added−17 removed

modified:requests/adapters.py+2 added-2 removed
13 unmodified lines
14from .packages.urllib3.poolmanager import PoolManager, ProxyManager15from .packages.urllib3.response import HTTPResponse16from .compat import urlparse, basestring, urldefrag, unquote17from .utils import (DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers,18 prepend_scheme_if_needed, get_auth_from_url)18 except_on_missing_scheme, get_auth_from_url)19from .structures import CaseInsensitiveDict20from .packages.urllib3.exceptions import MaxRetryError21from .packages.urllib3.exceptions import TimeoutError22from .packages.urllib3.exceptions import SSLError as _SSLError
169 unmodified lines
192 proxies = proxies or {}193 proxy = proxies.get(urlparse(url.lower()).scheme)194195 if proxy:196 proxy = prepend_scheme_if_needed(proxy, urlparse(url.lower()).scheme)196 except_on_missing_scheme(proxy)197 conn = ProxyManager(self.poolmanager.connection_from_url(proxy))198 else:199 conn = self.poolmanager.connection_from_url(url.lower())200
142 unmodified lines
modified:requests/utils.py+11 added-15 removed
23 unmodified lines
24from .compat import quote, urlparse, bytes, str, OrderedDict, urlunparse25from .compat import getproxies, proxy_bypass26from .cookies import RequestsCookieJar, cookiejar_from_dict27from .structures import CaseInsensitiveDict28from .exceptions import MissingSchema2930_hush_pyflakes = (RequestsCookieJar,)3132NETRC_FILES = ('.netrc', '_netrc')
360 unmodified lines
393 # First check whether no_proxy is defined. If it is, check that the URL394 # we're getting isn't in the no_proxy list.395 no_proxy = get_proxy('no_proxy')396 netloc = urlparse(url).netloc396 397398 if no_proxy:399 # We need to check whether we match here. We need to see if we match400 # the end of the netloc, both with and without the port.401 no_proxy = no_proxy.split(',')401 402403 for host in no_proxy:404 if netloc.endswith(host) or netloc.split(':')[0].endswith(host):405 # The URL does match something in no_proxy, so we don't want406 # to apply the proxies on this URL.407 return {}407 408409 # If the system proxy settings indicate that this URL should be bypassed,410 # don't proxy.411 if proxy_bypass(netloc):412 return {}
1 unmodified line
414 # If we get here, we either didn't have no_proxy set or we're not going415 # anywhere that no_proxy applies to, and the system settings don't require416 # bypassing the proxy for the current URL.417 return getproxies()417 418419420def default_user_agent():421 """Return a string representing the default user agent."""422 _implementation = platform.python_implementation()423
100 unmodified lines
524 # Did not detect a valid UTF-32 ascii-range character525 return None526527527def prepend_scheme_if_needed(url, new_scheme):528 '''Given a URL that may or may not have a scheme, prepend the given scheme.529 Does not replace a present scheme with the one provided as an argument.'''530 scheme, netloc, path, params, query, fragment = urlparse(url, new_scheme)528def except_on_missing_scheme(url):529 """Given a URL, raise a MissingSchema exception if the scheme is missing.530 """531 scheme, netloc, path, params, query, fragment = urlparse(url)532532 # urlparse is a finicky beast, and sometimes decides that there isn't a533 # netloc present. Assume that it's being over-cautious, and switch netloc534 # and path if urlparse decided there was no netloc.535 if not netloc:536 netloc, path = path, netloc533 if not scheme:534 raise MissingSchema('Proxy URLs must have explicit schemes.')535538 return urlunparse((scheme, netloc, path, params, query, fragment))536540537def get_auth_from_url(url):538 """Given a url with authentication components, extract them into a tuple of539 username,password."""540 if url:
4 unmodified lines