Merge branch 'proxy_auth' of https://github.com/chrisguitarguy/requests into develop

This commit is contained in:
Kenneth Reitz
2011-12-18 19:11:39 -05:00
2 changed files with 15 additions and 1 deletions
+8
View File
@@ -35,6 +35,14 @@ class HTTPBasicAuth(AuthBase):
return r
class HTTPProxyAuth(HTTPBasicAuth):
"""Attaches HTTP Proxy Authenetication to a given Request object."""
def __call__(self, r):
auth_s = b64encode('%s:%s' % (self.username, self.password))
r.headers['Proxy-Authorization'] = ('Basic %s' % auth_s)
return r
class HTTPDigestAuth(AuthBase):
"""Attaches HTTP Digest Authentication to the given Request object."""
def __init__(self, username, password):
+7 -1
View File
@@ -17,7 +17,7 @@ from .hooks import dispatch_hook
from .structures import CaseInsensitiveDict
from .status_codes import codes
from .packages import oreos
from .auth import HTTPBasicAuth
from .auth import HTTPBasicAuth, HTTPProxyAuth
from .packages.urllib3.exceptions import MaxRetryError
from .packages.urllib3.exceptions import SSLError as _SSLError
from .packages.urllib3.exceptions import HTTPError as _HTTPError
@@ -407,6 +407,12 @@ class Request(object):
if proxy:
conn = poolmanager.proxy_from_url(proxy)
_proxy = urlparse(proxy)
if '@' in _proxy.netloc:
auth, url = _proxy.netloc.split('@', 1)
self.proxy_auth = HTTPProxyAuth(*auth.split(':', 1))
r = self.proxy_auth(self)
self.__dict__.update(r.__dict__)
else:
# Check to see if keep_alive is allowed.
if self.config.get('keep_alive'):