Revert "Proxy urls should have explicit schemes."
authorschlamar <marc.schlaich@gmail.com>
Tue, 18 Feb 2014 14:15:36 +0000 (15:15 +0100)
committerschlamar <marc.schlaich@gmail.com>
Tue, 18 Feb 2014 14:15:36 +0000 (15:15 +0100)
This reverts commit 840540b6b1f07ef87faab73392c03fbef0dcc9fe.

Conflicts:
requests/adapters.py
requests/utils.py

requests/adapters.py
requests/utils.py

index ca462232c8f4c402a58d3c1908809a65a0b2838c..d51a5fe323c3ac9083f52a6193e74076dad21aed 100644 (file)
@@ -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:
index 7b7ff0a7bfb3a399caa8a2165f757f818a7130eb..5a3df4f75d4295cddd9592250eb487b885b901d8 100644 (file)
@@ -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):