# HG changeset patch # User Wagner Bruna # Date 2010-08-13 16:32:05 # Node ID 6c51a50560207670b155bda70a20d84eeaf575da # Parent 00f8e78376685c4f2f22ee1a07e757618b30f94c 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. diff --git a/mercurial/url.py b/mercurial/url.py --- a/mercurial/url.py +++ b/mercurial/url.py @@ -570,6 +570,25 @@ class httpdigestauthhandler(urllib2.HTTP 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 @@ def opener(ui, authinfo=None): 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)