# HG changeset patch # User Benoit Boissinot # Date 1168269509 -3600 # Node ID 8520a773a141e607df5ce4c676cd2e3d8c308fe7 # Parent d8b3edf88af09d2ba530c396ff18157ad7b3871e fix for digest auth when using keepalive.py The problem was with python > 2.3 which stores part of the headers in unredirected_hdrs. Furthermore, we simplify the code to use httplib directly. fix issue473 diff --git a/mercurial/keepalive.py b/mercurial/keepalive.py --- a/mercurial/keepalive.py +++ b/mercurial/keepalive.py @@ -17,6 +17,9 @@ # This file is part of urlgrabber, a high-level cross-protocol url-grabber # Copyright 2002-2004 Michael D. Stenner, Ryan Tomayko +# Modified by Benoit Boissinot: +# - fix for digest auth (inspired from urllib2.py @ Python v2.4) + """An HTTP handler for urllib2 that supports HTTP 1.1 and keepalive. >>> import urllib2 @@ -302,28 +305,15 @@ class HTTPHandler(urllib2.HTTPHandler): return r def _start_transaction(self, h, req): + headers = req.headers.copy() + body = req.data + if sys.version_info >= (2, 4): + headers.update(req.unredirected_hdrs) try: - if req.has_data(): - data = req.get_data() - h.putrequest('POST', req.get_selector()) - if not req.headers.has_key('Content-type'): - h.putheader('Content-type', - 'application/x-www-form-urlencoded') - if not req.headers.has_key('Content-length'): - h.putheader('Content-length', '%d' % len(data)) - else: - h.putrequest('GET', req.get_selector()) - except (socket.error, httplib.HTTPException), err: + h.request(req.get_method(), req.get_selector(), body, headers) + except socket.error, err: # XXX what error? raise urllib2.URLError(err) - for args in self.parent.addheaders: - h.putheader(*args) - for k, v in req.headers.items(): - h.putheader(k, v) - h.endheaders() - if req.has_data(): - h.send(data) - class HTTPResponse(httplib.HTTPResponse): # we need to subclass HTTPResponse in order to # 1) add readline() and readlines() methods