Skip to content
Myr

Merge pull request #1071 from Lukasa/master

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

Proxies should have schemes.

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 594716a, 054e1ab · Browse files · 2 files+18 added−2 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+18 added−2 removed

  • other:+18 added−2 removed

2 files+18 added−2 removed

modified:requests/adapters.py+3 added-1 removed
12 unmodified lines
13from .models import Response14from .packages.urllib3.poolmanager import PoolManager, proxy_from_url15from .hooks import dispatch_hook16from .compat import urlparse, basestring, urldefrag17from .utils import DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers17from .utils import (DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers,18 prepend_scheme_if_needed)19from .structures import CaseInsensitiveDict20from .packages.urllib3.exceptions import MaxRetryError21from .packages.urllib3.exceptions import TimeoutError22from .packages.urllib3.exceptions import SSLError as _SSLError
93 unmodified lines
116 proxies = proxies or {}117 proxy = proxies.get(urlparse(url).scheme)118119 if proxy:120 proxy = prepend_scheme_if_needed(proxy, urlparse(url).scheme)121 conn = proxy_from_url(proxy)122 else:123 conn = self.poolmanager.connection_from_url(url)124
69 unmodified lines
modified:requests/utils.py+15 added-1 removed
19 unmodified lines
2021from . import __version__22from . import certs23from .compat import parse_http_list as _parse_list_header24from .compat import quote, urlparse, bytes, str, OrderedDict24from .compat import quote, urlparse, bytes, str, OrderedDict, urlunparse25from .cookies import RequestsCookieJar, cookiejar_from_dict2627_hush_pyflakes = (RequestsCookieJar,)28
531 unmodified lines
560 if sample[1:] == _null3:561 return 'utf-32-le'562 # Did not detect a valid UTF-32 ascii-range character563 return None564565566def prepend_scheme_if_needed(url, new_scheme):567 '''Given a URL that may or may not have a scheme, prepend the given scheme.568 Does not replace a present scheme with the one provided as an argument.'''569 scheme, netloc, path, params, query, fragment = urlparse(url, new_scheme)570571 # urlparse is a finicky beast, and sometimes decides that there isn't a572 # netloc present. Assume that it's being over-cautious, and switch netloc573 # and path if urlparse decided there was no netloc.574 if not netloc:575 netloc, path = path, netloc576577 return urlunparse((scheme, netloc, path, params, query, fragment))