From: schlamar Date: Tue, 18 Feb 2014 14:15:36 +0000 (+0100) Subject: Revert "Proxy urls should have explicit schemes." X-Git-Tag: v2.3.0~5^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=780ce3902eccc7f7087e195211daf4c592cb28fb;p=services%2Fpython-requests.git Revert "Proxy urls should have explicit schemes." This reverts commit 840540b6b1f07ef87faab73392c03fbef0dcc9fe. Conflicts: requests/adapters.py requests/utils.py --- diff --git a/requests/adapters.py b/requests/adapters.py index ca46223..d51a5fe 100644 --- a/requests/adapters.py +++ b/requests/adapters.py @@ -16,7 +16,7 @@ from .packages.urllib3.response import HTTPResponse from .packages.urllib3.util import Timeout as TimeoutSauce from .compat import urlparse, basestring, urldefrag, unquote from .utils import (DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers, - except_on_missing_scheme, get_auth_from_url) + prepend_scheme_if_needed, get_auth_from_url) from .structures import CaseInsensitiveDict from .packages.urllib3.exceptions import MaxRetryError from .packages.urllib3.exceptions import TimeoutError @@ -203,7 +203,7 @@ class HTTPAdapter(BaseAdapter): proxy = proxies.get(urlparse(url.lower()).scheme) if proxy: - except_on_missing_scheme(proxy) + proxy = prepend_scheme_if_needed(proxy, urlparse(url.lower()).scheme) proxy_headers = self.proxy_headers(proxy) if not proxy in self.proxy_manager: diff --git a/requests/utils.py b/requests/utils.py index 7b7ff0a..5a3df4f 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -24,10 +24,10 @@ from . import __version__ from . import certs from .compat import parse_http_list as _parse_list_header from .compat import (quote, urlparse, bytes, str, OrderedDict, unquote, is_py2, - builtin_str, getproxies, proxy_bypass) + builtin_str, getproxies, proxy_bypass, urlunparse) from .cookies import RequestsCookieJar, cookiejar_from_dict from .structures import CaseInsensitiveDict -from .exceptions import MissingSchema, InvalidURL +from .exceptions import InvalidURL _hush_pyflakes = (RequestsCookieJar,) @@ -622,13 +622,18 @@ def guess_json_utf(data): return None -def except_on_missing_scheme(url): - """Given a URL, raise a MissingSchema exception if the scheme is missing. - """ - scheme, netloc, path, params, query, fragment = urlparse(url) +def prepend_scheme_if_needed(url, new_scheme): + '''Given a URL that may or may not have a scheme, prepend the given scheme. + Does not replace a present scheme with the one provided as an argument.''' + scheme, netloc, path, params, query, fragment = urlparse(url, new_scheme) + + # urlparse is a finicky beast, and sometimes decides that there isn't a + # netloc present. Assume that it's being over-cautious, and switch netloc + # and path if urlparse decided there was no netloc. + if not netloc: + netloc, path = path, netloc - if not scheme: - raise MissingSchema('Proxy URLs must have explicit schemes.') + return urlunparse((scheme, netloc, path, params, query, fragment)) def get_auth_from_url(url):