changeset 11844:6c51a5056020 stable

http basic auth: reset redirect counter on new requests (issue2255) On Python 2.6.6 (and patched 2.6.5 on certain Linux distros), the change that caused issue2255 was also applied to non-digest authentication; this change extends the 2ec346160783 fix accordingly.
author Wagner Bruna <wbruna@softwareexpress.com.br>
date Fri, 13 Aug 2010 13:32:05 -0300
parents 00f8e7837668
children 85de44ae0238
files mercurial/url.py
diffstat 1 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/url.py	Fri Aug 13 18:02:02 2010 +0200
+++ b/mercurial/url.py	Fri Aug 13 13:32:05 2010 -0300
@@ -570,6 +570,25 @@
                 return
             raise
 
+class httpbasicauthhandler(urllib2.HTTPBasicAuthHandler):
+    def __init__(self, *args, **kwargs):
+        urllib2.HTTPBasicAuthHandler.__init__(self, *args, **kwargs)
+        self.retried_req = None
+
+    def reset_retry_count(self):
+        # Python 2.6.5 will call this on 401 or 407 errors and thus loop
+        # forever. We disable reset_retry_count completely and reset in
+        # http_error_auth_reqed instead.
+        pass
+
+    def http_error_auth_reqed(self, auth_header, host, req, headers):
+        # Reset the retry counter once for each request.
+        if req is not self.retried_req:
+            self.retried_req = req
+            self.retried = 0
+        return urllib2.HTTPBasicAuthHandler.http_error_auth_reqed(
+                        self, auth_header, host, req, headers)
+
 def getauthinfo(path):
     scheme, netloc, urlpath, query, frag = urlparse.urlsplit(path)
     if not urlpath:
@@ -615,7 +634,7 @@
         ui.debug('http auth: user %s, password %s\n' %
                  (user, passwd and '*' * len(passwd) or 'not set'))
 
-    handlers.extend((urllib2.HTTPBasicAuthHandler(passmgr),
+    handlers.extend((httpbasicauthhandler(passmgr),
                      httpdigestauthhandler(passmgr)))
     handlers.extend([h(ui, passmgr) for h in handlerfuncs])
     opener = urllib2.build_opener(*handlers)