Merge pull request #1190 from mkomitee/master

Pass user options to hooks
This commit is contained in:
Kenneth Reitz
2013-03-02 13:04:00 -08:00
4 changed files with 17 additions and 5 deletions
+2 -2
View File
@@ -142,7 +142,7 @@ class HTTPDigestAuth(AuthBase):
return 'Digest %s' % (base)
def handle_401(self, r):
def handle_401(self, r, **kwargs):
"""Takes the given response and tries digest-auth, if needed."""
num_401_calls = getattr(self, 'num_401_calls', 1)
@@ -159,7 +159,7 @@ class HTTPDigestAuth(AuthBase):
r.raw.release_conn()
r.request.headers['Authorization'] = self.build_digest_header(r.request.method, r.request.url)
_r = r.connection.send(r.request)
_r = r.connection.send(r.request, **kwargs)
_r.history.append(r)
return _r
+2 -2
View File
@@ -26,7 +26,7 @@ def default_hooks():
# TODO: response is the only one
def dispatch_hook(key, hooks, hook_data):
def dispatch_hook(key, hooks, hook_data, **kwargs):
"""Dispatches a hook dictionary on a given piece of data."""
hooks = hooks or dict()
@@ -38,7 +38,7 @@ def dispatch_hook(key, hooks, hook_data):
hooks = [hooks]
for hook in hooks:
_hook_data = hook(hook_data)
_hook_data = hook(hook_data, **kwargs)
if _hook_data is not None:
hook_data = _hook_data
+1 -1
View File
@@ -419,7 +419,7 @@ class Session(SessionRedirectMixin):
r.elapsed = datetime.utcnow() - start
# Response manipulation hooks
r = dispatch_hook('response', hooks, r)
r = dispatch_hook('response', hooks, r, **kwargs)
# Redirect resolving generator.
gen = self.resolve_redirects(r, request, stream=stream,
+12
View File
@@ -172,6 +172,18 @@ class RequestsTestCase(unittest.TestCase):
r = s.get(url)
self.assertEqual(r.status_code, 200)
def test_DIGEST_STREAM(self):
auth = HTTPDigestAuth('user', 'pass')
url = httpbin('digest-auth', 'auth', 'user', 'pass')
r = requests.get(url, auth=auth, stream=True)
self.assertNotEqual(r.raw.read(), b'')
r = requests.get(url, auth=auth, stream=False)
self.assertEqual(r.raw.read(), b'')
def test_DIGESTAUTH_WRONG_HTTP_401_GET(self):
auth = HTTPDigestAuth('user', 'wrongpass')