Mercurial > hg > gitweb
comparison mercurial/keepalive.py @ 4026:8520a773a141
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
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Mon, 08 Jan 2007 16:18:29 +0100 |
parents | c4325f0a9b91 |
children |
comparison
equal
deleted
inserted
replaced
4025:d8b3edf88af0 | 4026:8520a773a141 |
---|---|
14 # 59 Temple Place, Suite 330, | 14 # 59 Temple Place, Suite 330, |
15 # Boston, MA 02111-1307 USA | 15 # Boston, MA 02111-1307 USA |
16 | 16 |
17 # This file is part of urlgrabber, a high-level cross-protocol url-grabber | 17 # This file is part of urlgrabber, a high-level cross-protocol url-grabber |
18 # Copyright 2002-2004 Michael D. Stenner, Ryan Tomayko | 18 # Copyright 2002-2004 Michael D. Stenner, Ryan Tomayko |
19 | |
20 # Modified by Benoit Boissinot: | |
21 # - fix for digest auth (inspired from urllib2.py @ Python v2.4) | |
19 | 22 |
20 """An HTTP handler for urllib2 that supports HTTP 1.1 and keepalive. | 23 """An HTTP handler for urllib2 that supports HTTP 1.1 and keepalive. |
21 | 24 |
22 >>> import urllib2 | 25 >>> import urllib2 |
23 >>> from keepalive import HTTPHandler | 26 >>> from keepalive import HTTPHandler |
300 if DEBUG: DEBUG.info("re-using connection to %s (%d)", host, id(h)) | 303 if DEBUG: DEBUG.info("re-using connection to %s (%d)", host, id(h)) |
301 | 304 |
302 return r | 305 return r |
303 | 306 |
304 def _start_transaction(self, h, req): | 307 def _start_transaction(self, h, req): |
305 try: | 308 headers = req.headers.copy() |
306 if req.has_data(): | 309 body = req.data |
307 data = req.get_data() | 310 if sys.version_info >= (2, 4): |
308 h.putrequest('POST', req.get_selector()) | 311 headers.update(req.unredirected_hdrs) |
309 if not req.headers.has_key('Content-type'): | 312 try: |
310 h.putheader('Content-type', | 313 h.request(req.get_method(), req.get_selector(), body, headers) |
311 'application/x-www-form-urlencoded') | 314 except socket.error, err: # XXX what error? |
312 if not req.headers.has_key('Content-length'): | |
313 h.putheader('Content-length', '%d' % len(data)) | |
314 else: | |
315 h.putrequest('GET', req.get_selector()) | |
316 except (socket.error, httplib.HTTPException), err: | |
317 raise urllib2.URLError(err) | 315 raise urllib2.URLError(err) |
318 | |
319 for args in self.parent.addheaders: | |
320 h.putheader(*args) | |
321 for k, v in req.headers.items(): | |
322 h.putheader(k, v) | |
323 h.endheaders() | |
324 if req.has_data(): | |
325 h.send(data) | |
326 | 316 |
327 class HTTPResponse(httplib.HTTPResponse): | 317 class HTTPResponse(httplib.HTTPResponse): |
328 # we need to subclass HTTPResponse in order to | 318 # we need to subclass HTTPResponse in order to |
329 # 1) add readline() and readlines() methods | 319 # 1) add readline() and readlines() methods |
330 # 2) add close_connection() methods | 320 # 2) add close_connection() methods |