Use user supplied options when resending authenticated requests
authorMichael Komitee <mkomitee@gmail.com>
Thu, 14 Feb 2013 00:11:38 +0000 (19:11 -0500)
committerMichael Komitee <mkomitee@gmail.com>
Thu, 14 Feb 2013 00:11:38 +0000 (19:11 -0500)
Hooks sometimes have to send requests (e.g. when responding to a 401 during
authentication).

All keyword arguments should be passed along when hooks are dispatched so that
if a user wanted to use a timeout, stream, specify a cert location with the
verify flag, etc, their specification can be followed.

requests/auth.py
requests/hooks.py
requests/sessions.py

index 1f8d659e3f5a49b9179ee5df2af42d4cf9cdf81d..805f2400da2443fd0ed037de09617a3dd7440f0e 100644 (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
index 8c661c67338618795658a1d66838b70d1a9bd03c..5dfaf6b68018885d099b2f6e8c7bb876a9cf29d3 100644 (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
 
index c53ccfc43727e9542ac3ca84508f0a1ce7c56e94..1ecc68f17e98dec8159255667aeea0585696f67b 100644 (file)
@@ -415,7 +415,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,