Fix infinite loop on wrong Digest Authentication (Issue #547)
authorVictoria Mo <vm2355@columbia.edu>
Sat, 14 Jul 2012 20:09:13 +0000 (16:09 -0400)
committerVictoria Mo <vm2355@columbia.edu>
Sat, 14 Jul 2012 20:09:13 +0000 (16:09 -0400)
Modified code to use the current fix versus the old fix, which was broken.

Co-Authored By: Timnit Gebru <tgebru@gmail.com>
Co-Authored By: Sarah Gonzalez <smar.gonz@gmail.com>
Co-Authored By: Leila Muhtasib <muhtasib@gmail.com>

requests/auth.py

index 0f98d28eed282149032c089f59257a4649e11376..5a196cb0acd7eeef36aaeafe6686902aceaa6556 100644 (file)
@@ -133,11 +133,11 @@ class HTTPDigestAuth(AuthBase):
     def handle_401(self, r):
         """Takes the given response and tries digest-auth, if needed."""
 
-        r.request.deregister_hook('response', self.handle_401)
-
+        num_401_calls = r.request.hooks['response'].count(self.handle_401)
+       
         s_auth = r.headers.get('www-authenticate', '')
 
-        if 'digest' in s_auth.lower():
+        if 'digest' in s_auth.lower() and num_401_calls < 2:
 
             last_nonce = ''
             nonce_count = 0