From 77b068bb9eb4364ad8c30bedf7654a0d77ebf9ff Mon Sep 17 00:00:00 2001 From: Michael Hunsinger Date: Sun, 21 Aug 2016 10:52:24 -0600 Subject: [PATCH] Fixed bug to give scheme proxy priority over "all" --- AUTHORS.rst | 1 + requests/utils.py | 4 ++-- tests/test_utils.py | 8 ++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 0654190b..289f1aef 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -168,3 +168,4 @@ Patches and Suggestions - Jesse Shapiro (`@haikuginger `_) - Nate Prewitt (`@nateprewitt `_) - Maik Himstedt +- Michael Hunsinger diff --git a/requests/utils.py b/requests/utils.py index dfeb77d9..e0bb3e7c 100644 --- a/requests/utils.py +++ b/requests/utils.py @@ -620,10 +620,10 @@ def select_proxy(url, proxies): return proxies.get('all', proxies.get(urlparts.scheme)) proxy_keys = [ - 'all://' + urlparts.hostname, - 'all', urlparts.scheme + '://' + urlparts.hostname, urlparts.scheme, + 'all://' + urlparts.hostname, + 'all', ] proxy = None for proxy_key in proxy_keys: diff --git a/tests/test_utils.py b/tests/test_utils.py index 2e28c068..b4fc9483 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -323,6 +323,9 @@ http_proxies = {'http': 'http://http.proxy', 'http://some.host': 'http://some.host.proxy'} all_proxies = {'all': 'socks5://http.proxy', 'all://some.host': 'socks5://some.host.proxy'} +mixed_proxies = {'http': 'http://http.proxy', + 'http://some.host': 'http://some.host.proxy', + 'all': 'socks5://http.proxy'} @pytest.mark.parametrize( 'url, expected, proxies', ( ('hTTp://u:p@Some.Host/path', 'http://some.host.proxy', http_proxies), @@ -336,6 +339,11 @@ all_proxies = {'all': 'socks5://http.proxy', ('hTTp:///path', 'socks5://http.proxy', all_proxies), ('hTTps://Other.Host', 'socks5://http.proxy', all_proxies), + ('http://u:p@other.host/path', 'http://http.proxy', mixed_proxies), + ('http://u:p@some.host/path', 'http://some.host.proxy', mixed_proxies), + ('https://u:p@other.host/path', 'socks5://http.proxy', mixed_proxies), + ('https://u:p@some.host/path', 'socks5://http.proxy', mixed_proxies), + # XXX: unsure whether this is reasonable behavior ('file:///etc/motd', 'socks5://http.proxy', all_proxies), ))