Skip to content
Myr

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

2 files+15 added−10 removed

modified:requests/adapters.py+2 added-2 removed
14 unmodified lines
15from .packages.urllib3.response import HTTPResponse16from .packages.urllib3.util import Timeout as TimeoutSauce17from .compat import urlparse, basestring, urldefrag, unquote18from .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)20from .structures import CaseInsensitiveDict21from .packages.urllib3.exceptions import MaxRetryError22from .packages.urllib3.exceptions import TimeoutError23from .packages.urllib3.exceptions import SSLError as _SSLError
178 unmodified lines
202 proxies = proxies or {}203 proxy = proxies.get(urlparse(url.lower()).scheme)204205 if proxy:206 except_on_missing_scheme(proxy)206 proxy = prepend_scheme_if_needed(proxy, 'http')207 proxy_headers = self.proxy_headers(proxy)208209 if not proxy in self.proxy_manager:210 self.proxy_manager[proxy] = proxy_from_url(
183 unmodified lines
modified:requests/utils.py+13 added-8 removed
22 unmodified lines
23from . import __version__24from . import certs25from .compat import parse_http_list as _parse_list_header26from .compat import (quote, urlparse, bytes, str, OrderedDict, unquote, is_py2,27 builtin_str, getproxies, proxy_bypass)27 builtin_str, getproxies, proxy_bypass, urlunparse)28from .cookies import RequestsCookieJar, cookiejar_from_dict29from .structures import CaseInsensitiveDict30from .exceptions import MissingSchema, InvalidURL30from .exceptions import InvalidURL3132_hush_pyflakes = (RequestsCookieJar,)3334NETRC_FILES = ('.netrc', '_netrc')
591 unmodified lines
626 # Did not detect a valid UTF-32 ascii-range character627 return None628629630def 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)630def 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)634635 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, netloc640641 return urlunparse((scheme, netloc, path, params, query, fragment))642643644def 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