[PATCH] Keep authentication information after the first fail HTTP access (issue3567)

Nikolaj Sjujskij sterkrig at myopera.com
Fri Dec 20 08:20:45 CST 2013


On Fri, 20 Dec 2013 18:01:14 +0400, Stéphane Klein <sklein at bearstech.com>  
wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Le 14/12/13 18:49, Augie Fackler a écrit :
>> Aaaand I just backed it out, thanks to terrible breakage on Python 2.4.
>>
>> Sigh. Patch works great on 2.6 and 2.7, disaster on 2.4.
>
> This is a new version with python 2.4 bugfix.
>
> # HG changeset patch
> # User Stéphane Klein <contact at stephane-klein.info>
> # Date 1387547765 -3600
> #      Fri Dec 20 14:56:05 2013 +0100
> # Node ID ec0ec32a305f6626ccd9b79e4874ffbcd2e5ecd8
> # Parent  04036798ebed0c6d7062517bb49b308a15e4345e
> http: reuse authentication info after the first failed request  
> (issue3567)
I'm sure there were a lot more lines of description here in the first  
version. And I believe those were useful lines nobody objected to.


> diff -r 04036798ebed -r ec0ec32a305f mercurial/url.py
> - --- a/mercurial/url.py	Fri Nov 15 23:18:08 2013 -0500
> +++ b/mercurial/url.py	Fri Dec 20 14:56:05 2013 +0100
> @@ -8,6 +8,7 @@
>  # GNU General Public License version 2 or any later version.
>
>  import urllib, urllib2, httplib, os, socket, cStringIO
> +import base64
>  from i18n import _
>  import keepalive, util, sslutil
>  import httpconnection as httpconnectionmod
> @@ -418,9 +419,22 @@
>
>  class httpbasicauthhandler(urllib2.HTTPBasicAuthHandler):
>      def __init__(self, *args, **kwargs):
> +        self.auth = None
>          urllib2.HTTPBasicAuthHandler.__init__(self, *args, **kwargs)
>          self.retried_req = None
>
> +    def http_request(self, request):
> +        if self.auth:
> +            request.add_unredirected_header(self.auth_header, self.auth)
> +
> +        return request
> +
> +    def https_request(self, request):
> +        if self.auth:
> +            request.add_unredirected_header(self.auth_header, self.auth)
> +
> +        return request
> +
>      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
> @@ -435,6 +449,19 @@
>          return urllib2.HTTPBasicAuthHandler.http_error_auth_reqed(
>                          self, auth_header, host, req, headers)
>
> +    def retry_http_basic_auth(self, host, req, realm):
> +        user, pw = self.passwd.find_user_password(realm, host)
> +        if pw is not None:
> +            raw = "%s:%s" % (user, pw)
> +            auth = 'Basic %s' % base64.b64encode(raw).strip()
> +            if req.headers.get(self.auth_header, None) == auth:
> +                return None
> +            self.auth = auth
> +            req.add_unredirected_header(self.auth_header, auth)
> +            return self.parent.open(req)
> +        else:
> +            return None
> +
>  handlerfuncs = []
>
>  def opener(ui, authinfo=None):
>
>
> - --
> Stéphane Klein <sklein at bearstech.com>
> GSM : 06 61 48 76 04
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.12 (Darwin)
> Comment: GPGTools - http://gpgtools.org
> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>
> iF4EAREIAAYFAlK0TaoACgkQU9O4HJsr4Ywv3QEAr3jIgqCBKKhAGTiqqbtA8Ty0
> GYkzJCy3W78eR5I/cWQBAKDSfadY+NnQtRM/Sg1ywVUre8shdsZxPtSTzBiwUGi3
> =He/J
> -----END PGP SIGNATURE-----
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


-- 
Yrs sincerely,
Nikolaj Sjujskij


More information about the Mercurial-devel mailing list