mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merged changes from @lukasa
This commit is contained in:
@@ -286,10 +286,6 @@ class HTTPAdapter(BaseAdapter):
|
||||
username, password = get_auth_from_url(proxy)
|
||||
|
||||
if username and password:
|
||||
# Proxy auth usernames and passwords will be urlencoded, we need
|
||||
# to decode them.
|
||||
username = unquote(username)
|
||||
password = unquote(password)
|
||||
headers['Proxy-Authorization'] = _basic_auth_str(username,
|
||||
password)
|
||||
|
||||
|
||||
+7
-11
@@ -634,18 +634,14 @@ def except_on_missing_scheme(url):
|
||||
def get_auth_from_url(url):
|
||||
"""Given a url with authentication components, extract them into a tuple of
|
||||
username,password."""
|
||||
if url:
|
||||
parsed = urlparse(url)
|
||||
username = ""
|
||||
password = ""
|
||||
parsed = urlparse(url)
|
||||
|
||||
if parsed.username is not None:
|
||||
username = unquote(parsed.username)
|
||||
if parsed.password is not None:
|
||||
password = unquote(parsed.password)
|
||||
return (username, password)
|
||||
else:
|
||||
return ('', '')
|
||||
try:
|
||||
auth = (unquote(parsed.username), unquote(parsed.password))
|
||||
except (AttributeError, TypeError):
|
||||
auth = ('', '')
|
||||
|
||||
return auth
|
||||
|
||||
|
||||
def to_native_string(string, encoding='ascii'):
|
||||
|
||||
+5
-1
@@ -194,7 +194,7 @@ class RequestsTestCase(unittest.TestCase):
|
||||
assert r.json()['cookies']['foo'] == 'bar'
|
||||
# Make sure the session cj is still the custom one
|
||||
assert s.cookies is cj
|
||||
|
||||
|
||||
def test_param_cookiejar_works(self):
|
||||
cj = cookielib.CookieJar()
|
||||
cookiejar_from_dict({'foo' : 'bar'}, cj)
|
||||
@@ -705,6 +705,10 @@ class RequestsTestCase(unittest.TestCase):
|
||||
url = 'http://user%25user:pass@complex.url.com/path?query=yes'
|
||||
assert ('user%user', 'pass') == requests.utils.get_auth_from_url(url)
|
||||
|
||||
def test_get_auth_from_url_encoded_hashes(self):
|
||||
url = 'http://user:pass%23pass@complex.url.com/path?query=yes'
|
||||
assert ('user', 'pass#pass') == requests.utils.get_auth_from_url(url)
|
||||
|
||||
def test_cannot_send_unprepared_requests(self):
|
||||
r = requests.Request(url=HTTPBIN)
|
||||
with pytest.raises(ValueError):
|
||||
|
||||
Reference in New Issue
Block a user