Skip to content
Myr

Merge pull request #2253 from yossigo/digest_redirect_fix

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

A fix for #1979: repeat HTTP digest authentication after redirect.

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 124c094, 3d8823c · Browse files · 1 file+8 added−1 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−1 removed

  • other:+8 added−1 removed

1 file+8 added−1 removed

modified:requests/auth.py+8 added-1 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)153154 def handle_redirect(self, r, **kwargs):155 """Reset num_401_calls counter on redirects."""156 if r.is_redirect:157 setattr(self, 'num_401_calls', 1)158159 def handle_401(self, r, **kwargs):160 """Takes the given response and tries digest-auth, if needed."""161162 if self.pos is not None:
24 unmodified lines
187 _r.request = prep188189 return _r190185 setattr(self, 'num_401_calls', 1)191 setattr(self, 'num_401_calls', num_401_calls + 1)192 return r193194 def __call__(self, r):195 # If we have a saved nonce, skip the 401
3 unmodified lines
199 self.pos = r.body.tell()200 except AttributeError:201 pass202 r.register_hook('response', self.handle_401)203 r.register_hook('response', self.handle_redirect)204 return r