Merge pull request #1924 from schlamar/proxy-default-scheme
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Default proxy scheme to HTTP
authored by Kenneth Reitz · committed by Kenneth Reitz · parents 569cd23, 4404e7e · Browse files · 2 files·+15 added−10 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+15 added−10 removed
- other:+15 added−10 removed
Provenance
- Commit
c023f06- Tree
8330f3b- Author
Kenneth Reitz <me@kennethreitz.org>- Committer
Kenneth Reitz <me@kennethreitz.org>- Parent 1
569cd23- Parent 2
4404e7e
2 files changed+15 added−10 removed
modified:requests/adapters.py+2 added-2 removed
14 unmodified lines15 from .packages.urllib3.response import HTTPResponse16 from .packages.urllib3.util import Timeout as TimeoutSauce17 from .compat import urlparse, basestring, urldefrag, unquote18 from .utils import (DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers,19- except_on_missing_scheme, get_auth_from_url)19+ prepend_scheme_if_needed, get_auth_from_url)20 from .structures import CaseInsensitiveDict21 from .packages.urllib3.exceptions import MaxRetryError22 from .packages.urllib3.exceptions import TimeoutError23 from .packages.urllib3.exceptions import SSLError as _SSLError178 unmodified lines202 proxies = proxies or {}203 proxy = proxies.get(urlparse(url.lower()).scheme)204 205 if proxy:206- except_on_missing_scheme(proxy)206+ proxy = prepend_scheme_if_needed(proxy, 'http')207 proxy_headers = self.proxy_headers(proxy)208 209 if not proxy in self.proxy_manager:210 self.proxy_manager[proxy] = proxy_from_url(183 unmodified linesmodified:requests/utils.py+13 added-8 removed
22 unmodified lines23 from . import __version__24 from . import certs25 from .compat import parse_http_list as _parse_list_header26 from .compat import (quote, urlparse, bytes, str, OrderedDict, unquote, is_py2,27- builtin_str, getproxies, proxy_bypass)27+ builtin_str, getproxies, proxy_bypass, urlunparse)28 from .cookies import RequestsCookieJar, cookiejar_from_dict29 from .structures import CaseInsensitiveDict30-from .exceptions import MissingSchema, InvalidURL30+from .exceptions import InvalidURL31 32 _hush_pyflakes = (RequestsCookieJar,)33 34 NETRC_FILES = ('.netrc', '_netrc')591 unmodified lines626 # Did not detect a valid UTF-32 ascii-range character627 return None628 629 630-def except_on_missing_scheme(url):631- """Given a URL, raise a MissingSchema exception if the scheme is missing.632- """633- scheme, netloc, path, params, query, fragment = urlparse(url)630+def prepend_scheme_if_needed(url, new_scheme):631+ '''Given a URL that may or may not have a scheme, prepend the given scheme.632+ Does not replace a present scheme with the one provided as an argument.'''633+ scheme, netloc, path, params, query, fragment = urlparse(url, new_scheme)634 635- if not scheme:636- raise MissingSchema('Proxy URLs must have explicit schemes.')635+ # urlparse is a finicky beast, and sometimes decides that there isn't a636+ # netloc present. Assume that it's being over-cautious, and switch netloc637+ # and path if urlparse decided there was no netloc.638+ if not netloc:639+ netloc, path = path, netloc640 641+ return urlunparse((scheme, netloc, path, params, query, fragment))642 643+644 def get_auth_from_url(url):645 """Given a url with authentication components, extract them into a tuple of646 username,password."""647 parsed = urlparse(url)26 unmodified lines