From c97a530638bba86576f3e40b49cb0e061b790bdd Mon Sep 17 00:00:00 2001 From: Pawel Miech Date: Mon, 31 Oct 2016 14:42:01 +0100 Subject: [PATCH] [httpAdapter] allow empty password in proxy credentials fixes #3659 --- requests/adapters.py | 2 +- tests/test_requests.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/requests/adapters.py b/requests/adapters.py index 4a4c4e0e..2475879c 100644 --- a/requests/adapters.py +++ b/requests/adapters.py @@ -366,7 +366,7 @@ class HTTPAdapter(BaseAdapter): headers = {} username, password = get_auth_from_url(proxy) - if username and password: + if username: headers['Proxy-Authorization'] = _basic_auth_str(username, password) diff --git a/tests/test_requests.py b/tests/test_requests.py index 5a2608e2..5ce098d9 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -1472,6 +1472,16 @@ class TestRequests: proxies['one'].clear.assert_called_once_with() proxies['two'].clear.assert_called_once_with() + def test_proxy_auth(self, httpbin): + adapter = HTTPAdapter() + headers = adapter.proxy_headers("http://user:pass@httpbin.org") + assert headers == {'Proxy-Authorization': 'Basic dXNlcjpwYXNz'} + + def test_proxy_auth_empty_pass(self, httpbin): + adapter = HTTPAdapter() + headers = adapter.proxy_headers("http://user:@httpbin.org") + assert headers == {'Proxy-Authorization': 'Basic dXNlcjo='} + def test_response_json_when_content_is_None(self, httpbin): r = requests.get(httpbin('/status/204')) # Make sure r.content is None