Skip to content
Myr

Merge pull request #1190 from mkomitee/master

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

Pass user options to hooks

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 7aad3fd, 4c21106 · Browse files · 4 files+17 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

4 files+17 added−5 removed

  • other:+17 added−5 removed

4 files+17 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
417 unmodified lines
418 # Total elapsed time of the request (approximately)419 r.elapsed = datetime.utcnow() - start420421 # Response manipulation hooks422 r = dispatch_hook('response', hooks, r)422 r = dispatch_hook('response', hooks, r, **kwargs)423424 # Redirect resolving generator.425 gen = self.resolve_redirects(r, request, stream=stream,426 timeout=timeout, max_retries=max_retries,
47 unmodified lines
modified:test_requests.py+12 added
170 unmodified lines
171 s.auth = auth172 r = s.get(url)173 self.assertEqual(r.status_code, 200)174175 def test_DIGEST_STREAM(self):176177 auth = HTTPDigestAuth('user', 'pass')178 url = httpbin('digest-auth', 'auth', 'user', 'pass')179180 r = requests.get(url, auth=auth, stream=True)181 self.assertNotEqual(r.raw.read(), b'')182183 r = requests.get(url, auth=auth, stream=False)184 self.assertEqual(r.raw.read(), b'')185186187 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self):188189 auth = HTTPDigestAuth('user', 'wrongpass')190 url = httpbin('digest-auth', 'auth', 'user', 'pass')
201 unmodified lines