Skip to content
Myr

Merge pull request #2389 from sigmavirus24/bug/fix-digest-auth

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

Fix bug in renegotiating a nonce with the server

authored by Ian Cordasco · committed by Ian Cordasco · parents bd3cf95, 86c3ecf · Browse files · 1 file+4 added−3 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+4 added−3 removed

  • other:+4 added−3 removed

1 file+4 added−3 removed

modified:requests/auth.py+4 added-3 removed
65 unmodified lines
66 self.last_nonce = ''67 self.nonce_count = 068 self.chal = {}69 self.pos = None70 self.num_401_calls = 17172 def build_digest_header(self, method, url):7374 realm = self.chal['realm']
79 unmodified lines
154155 def handle_redirect(self, r, **kwargs):156 """Reset num_401_calls counter on redirects."""157 if r.is_redirect:157 setattr(self, 'num_401_calls', 1)158 self.num_401_calls = 1159160 def handle_401(self, r, **kwargs):161 """Takes the given response and tries digest-auth, if needed."""162
5 unmodified lines
168 s_auth = r.headers.get('www-authenticate', '')169170 if 'digest' in s_auth.lower() and num_401_calls < 2:171171 setattr(self, 'num_401_calls', num_401_calls + 1)172 self.num_401_calls += 1173 pat = re.compile(r'digest ', flags=re.IGNORECASE)174 self.chal = parse_dict_header(pat.sub('', s_auth, count=1))175176 # Consume content and release the original connection
11 unmodified lines
188 _r.request = prep189190 return _r191191 setattr(self, 'num_401_calls', num_401_calls + 1)192 self.num_401_calls = 1193 return r194195 def __call__(self, r):196 # If we have a saved nonce, skip the 401
13 unmodified lines