Skip to content
Myr

Clean up, support all redirects, fix potential endless 401 loop.

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

authored by Yossi Gottlieb · committed by Yossi Gottlieb · parent c28da22 · Browse files · 1 file+8 added−8 removed
This commit

State

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

Diff stats

1 file+8 added−8 removed

  • other:+8 added−8 removed

1 file+8 added−8 removed

modified:requests/auth.py+8 added-8 removed
15 unmodified lines
1617from .compat import urlparse, str18from .cookies import extract_cookies_to_jar19from .utils import parse_dict_header, to_native_string20from .status_codes import codes2122CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded'23CONTENT_TYPE_MULTI_PART = 'multipart/form-data'24
125 unmodified lines
150 base += ', qop="auth", nc=%s, cnonce="%s"' % (ncvalue, cnonce)151152 return 'Digest %s' % (base)153153 def handle_302(self, r, **kwargs):154 def handle_redirect(self, r, **kwargs):155 """Reset num_401_calls counter on redirects."""155 try:156 delattr(self, 'num_401_calls')157 except AttributeError:158 pass159 return r156 if r.status_code in (157 codes.temporary_redirect,158 codes.permanent_redirect):159 setattr(self, 'num_401_calls', 1)160161 def handle_401(self, r, **kwargs):162 """Takes the given response and tries digest-auth, if needed."""163
25 unmodified lines
189 _r.request = prep190191 return _r192193 setattr(self, 'num_401_calls', 1)193 setattr(self, 'num_401_calls', num_401_calls + 1)194 return r195196 def __call__(self, r):197 # If we have a saved nonce, skip the 401
3 unmodified lines
201 self.pos = r.body.tell()202 except AttributeError:203 pass204 r.register_hook('response', self.handle_401)205 r.register_hook('response', self.handle_302)205 r.register_hook('response', self.handle_redirect)206 return r