keepalive: attempt to fix issue1003
authorMatt Mackall <mpm@selenic.com>
Thu, 23 Apr 2009 15:40:10 -0500
changeset 8146 4f13ed6ee544
parent 8145 0c2ba48415c8
child 8147 441dc7becd43
keepalive: attempt to fix issue1003 This is a reimport of the relevant piece of the upstream urlgrabber, which appears to be more correct.
mercurial/keepalive.py
--- 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