Skip to content

Commit

Permalink
Fixed bug to give scheme proxy priority over "all"
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Hunsinger committed Aug 21, 2016
1 parent d3567aa commit 77b068b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Expand Up @@ -168,3 +168,4 @@ Patches and Suggestions
- Jesse Shapiro <jesse@jesseshapiro.net> (`@haikuginger <https://github.com/haikuginger>`_)
- Nate Prewitt <nate.prewitt@gmail.com> (`@nateprewitt <https://github.com/nateprewitt>`_)
- Maik Himstedt
- Michael Hunsinger
4 changes: 2 additions & 2 deletions requests/utils.py
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_utils.py
Expand Up @@ -323,6 +323,9 @@ def test_dotted_netmask(mask, expected):
'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),
Expand All @@ -336,6 +339,11 @@ def test_dotted_netmask(mask, expected):
('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),
))
Expand Down

0 comments on commit 77b068b

Please sign in to comment.