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
Provenance
- Commit
d372a5b- Tree
c0a6aaa- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
7aad3fd- Parent 2
4c21106
4 files changed+17 added−5 removed
modified:requests/auth.py+2 added-2 removed
140 unmodified lines141 base += ', qop=auth, nc=%s, cnonce="%s"' % (ncvalue, cnonce)142 143 return 'Digest %s' % (base)144 145- def handle_401(self, r):145+ def handle_401(self, r, **kwargs):146 """Takes the given response and tries digest-auth, if needed."""147 148 num_401_calls = getattr(self, 'num_401_calls', 1)149 s_auth = r.headers.get('www-authenticate', '')8 unmodified lines158 r.content159 r.raw.release_conn()160 161 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)164 165 return _r166 9 unmodified linesmodified:requests/hooks.py+2 added-2 removed
24 unmodified lines25 26 # TODO: response is the only one27 28 29-def dispatch_hook(key, hooks, hook_data):29+def dispatch_hook(key, hooks, hook_data, **kwargs):30 """Dispatches a hook dictionary on a given piece of data."""31 32 hooks = hooks or dict()33 3 unmodified lines37 if hasattr(hooks, '__call__'):38 hooks = [hooks]39 40 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_data44 45 return hook_datamodified:requests/sessions.py+1 added-1 removed
417 unmodified lines418 # Total elapsed time of the request (approximately)419 r.elapsed = datetime.utcnow() - start420 421 # Response manipulation hooks422- r = dispatch_hook('response', hooks, r)422+ r = dispatch_hook('response', hooks, r, **kwargs)423 424 # Redirect resolving generator.425 gen = self.resolve_redirects(r, request, stream=stream,426 timeout=timeout, max_retries=max_retries,47 unmodified linesmodified:test_requests.py+12 added
170 unmodified lines171 s.auth = auth172 r = s.get(url)173 self.assertEqual(r.status_code, 200)174 175+ def test_DIGEST_STREAM(self):176+177+ auth = HTTPDigestAuth('user', 'pass')178+ url = httpbin('digest-auth', 'auth', 'user', 'pass')179+180+ r = requests.get(url, auth=auth, stream=True)181+ self.assertNotEqual(r.raw.read(), b'')182+183+ r = requests.get(url, auth=auth, stream=False)184+ self.assertEqual(r.raw.read(), b'')185+186+187 def test_DIGESTAUTH_WRONG_HTTP_401_GET(self):188 189 auth = HTTPDigestAuth('user', 'wrongpass')190 url = httpbin('digest-auth', 'auth', 'user', 'pass')201 unmodified lines