Skip to content
Myr

Use user supplied options when resending authenticated requests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Michael Komitee · committed by Michael Komitee · parent f73bda0 · Browse files · 3 files+5 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+5 added−5 removed

  • other:+5 added−5 removed

3 files+5 added−5 removed

modified:requests/auth.py+2 added-2 removed
140 unmodified lines
141 base += ', qop=auth, nc=%s, cnonce="%s"' % (ncvalue, cnonce)142143 return 'Digest %s' % (base)144145 def handle_401(self, r):145 def handle_401(self, r, **kwargs):146 """Takes the given response and tries digest-auth, if needed."""147148 num_401_calls = getattr(self, 'num_401_calls', 1)149 s_auth = r.headers.get('www-authenticate', '')
8 unmodified lines
158 r.content159 r.raw.release_conn()160161 r.request.headers['Authorization'] = self.build_digest_header(r.request.method, r.request.url)162 _r = r.connection.send(r.request)162 _r = r.connection.send(r.request, **kwargs)163 _r.history.append(r)164165 return _r166
9 unmodified lines
modified:requests/hooks.py+2 added-2 removed
24 unmodified lines
2526# TODO: response is the only one272829def dispatch_hook(key, hooks, hook_data):29def dispatch_hook(key, hooks, hook_data, **kwargs):30 """Dispatches a hook dictionary on a given piece of data."""3132 hooks = hooks or dict()33
3 unmodified lines
37 if hasattr(hooks, '__call__'):38 hooks = [hooks]3940 for hook in hooks:41 _hook_data = hook(hook_data)41 _hook_data = hook(hook_data, **kwargs)42 if _hook_data is not None:43 hook_data = _hook_data4445 return hook_data
modified:requests/sessions.py+1 added-1 removed
413 unmodified lines
414 # Total elapsed time of the request (approximately)415 r.elapsed = datetime.utcnow() - start416417 # Response manipulation hooks418 r = dispatch_hook('response', hooks, r)418 r = dispatch_hook('response', hooks, r, **kwargs)419420 # Redirect resolving generator.421 gen = self.resolve_redirects(r, request, stream=stream,422 timeout=timeout, verify=verify, cert=cert,
46 unmodified lines