keepalive: attempt to fix
issue1003
This is a reimport of the relevant piece of the upstream urlgrabber,
which appears to be more correct.
--- a/mercurial/keepalive.py Thu Apr 23 15:40:10 2009 -0500
+++ b/mercurial/keepalive.py Thu Apr 23 15:40:10 2009 -0500
@@ -307,15 +307,28 @@
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:
- h.request(req.get_method(), req.get_selector(), body, headers)
- except socket.error, err: # XXX what error?
+ if req.has_data():
+ data = req.get_data()
+ h.putrequest('POST', req.get_selector())
+ if 'Content-type' not in req.headers:
+ h.putheader('Content-type',
+ 'application/x-www-form-urlencoded')
+ if 'Content-length' not in req.headers:
+ h.putheader('Content-length', '%d' % len(data))
+ else:
+ h.putrequest('GET', req.get_selector())
+ except (socket.error), err:
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 HTTPHandler(KeepAliveHandler, urllib2.HTTPHandler):
pass