diff options
author | Kenneth Reitz <me@kennethreitz.org> | 2014-10-05 13:19:14 -0400 |
---|---|---|
committer | Kenneth Reitz <me@kennethreitz.org> | 2014-10-05 13:19:14 -0400 |
commit | 5850b1f53b98ba48c23432475b246cddf9f489d4 (patch) | |
tree | f306a2671a74b45c1cf6f7bf149bb6cf2a6d76b4 | |
parent | 779c001e44ed436a805a6fea5b4d2895b381d7b3 (diff) | |
parent | cd5eb629616012fcfa2835a633e04cdc47c33ec9 (diff) | |
download | python-requests-5850b1f53b98ba48c23432475b246cddf9f489d4.tar.gz |
Merge pull request #2249 from t-8ch/fix_2247
fix #2247
-rw-r--r-- | requests/adapters.py | 6 | ||||
-rw-r--r-- | requests/utils.py | 15 |
2 files changed, 18 insertions, 3 deletions
diff --git a/requests/adapters.py b/requests/adapters.py index d17d9e69..abb25d11 100644 --- a/requests/adapters.py +++ b/requests/adapters.py @@ -15,9 +15,9 @@ from .packages.urllib3 import Retry from .packages.urllib3.poolmanager import PoolManager, proxy_from_url from .packages.urllib3.response import HTTPResponse from .packages.urllib3.util import Timeout as TimeoutSauce -from .compat import urlparse, basestring, urldefrag +from .compat import urlparse, basestring from .utils import (DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers, - prepend_scheme_if_needed, get_auth_from_url) + prepend_scheme_if_needed, get_auth_from_url, urldefragauth) from .structures import CaseInsensitiveDict from .packages.urllib3.exceptions import ConnectTimeoutError from .packages.urllib3.exceptions import HTTPError as _HTTPError @@ -270,7 +270,7 @@ class HTTPAdapter(BaseAdapter): proxy = proxies.get(scheme) if proxy and scheme != 'https': - url, _ = urldefrag(request.url) + url = urldefragauth(request.url) else: url = request.path_url diff --git a/requests/utils.py b/requests/utils.py index 5d34ab55..1868f861 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -669,3 +669,18 @@ def to_native_string(string, encoding='ascii'): out = string.decode(encoding) return out + + +def urldefragauth(url): + """ + Given a url remove the fragment and the authentication part + """ + scheme, netloc, path, params, query, fragment = urlparse(url) + + # see func:`prepend_scheme_if_needed` + if not netloc: + netloc, path = path, netloc + + netloc = netloc.rsplit('@', 1)[-1] + + return urlunparse((scheme, netloc, path, params, query, '')) |