From: Michael Komitee Date: Thu, 14 Feb 2013 00:11:38 +0000 (-0500) Subject: Use user supplied options when resending authenticated requests X-Git-Tag: v1.2.0~28^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d0285fac4203e8cfed6b5ceeb96b2646076e745d;p=services%2Fpython-requests.git Use user supplied options when resending authenticated requests 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. --- diff --git a/requests/auth.py b/requests/auth.py index 1f8d659..805f240 100644 --- a/requests/auth.py +++ b/requests/auth.py @@ -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 diff --git a/requests/hooks.py b/requests/hooks.py index 8c661c6..5dfaf6b 100644 --- a/requests/hooks.py +++ b/requests/hooks.py @@ -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 diff --git a/requests/sessions.py b/requests/sessions.py index c53ccfc..1ecc68f 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -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,