keepalive: fix 4f13ed6ee544, reintroduce unredirected_hdrs
authorPatrick Mezard <pmezard@gmail.com>
Mon, 27 Apr 2009 22:15:36 +0200
changeset 8233 655c435efe92
parent 8232 823f25b25dea
child 8234 27dbe534397b
keepalive: fix 4f13ed6ee544, reintroduce unredirected_hdrs The previous fix dropped unredirected_hdrs which contain authentication headers. Removing them break POST request requiring authentication (like unbundle calls to bitbucket.org).
mercurial/keepalive.py
--- a/mercurial/keepalive.py	Sun Apr 26 01:57:12 2009 +0200
+++ b/mercurial/keepalive.py	Mon Apr 27 22:15:36 2009 +0200
@@ -307,23 +307,31 @@
         return r
 
     def _start_transaction(self, h, req):
+        # What follows mostly reimplements HTTPConnection.request()
+        # except it adds self.parent.addheaders in the mix.
+        headers = req.headers.copy()
+        if sys.version_info >= (2, 4):
+            headers.update(req.unredirected_hdrs)
+        headers.update(self.parent.addheaders)
+        headers = dict((n.lower(), v) for n,v in headers.items())
+        skipheaders = {}
+        for n in ('host', 'accept-encoding'):
+            if n in headers:
+                skipheaders['skip_' + n.replace('-', '_')] = 1
         try:
             if req.has_data():
                 data = req.get_data()
-                h.putrequest('POST', req.get_selector())
-                if 'Content-type' not in req.headers:
+                h.putrequest('POST', req.get_selector(), **skipheaders)
+                if 'content-type' not in headers:
                     h.putheader('Content-type',
                                 'application/x-www-form-urlencoded')
-                if 'Content-length' not in req.headers:
+                if 'content-length' not in headers:
                     h.putheader('Content-length', '%d' % len(data))
             else:
-                h.putrequest('GET', req.get_selector())
+                h.putrequest('GET', req.get_selector(), **skipheaders)
         except (socket.error), err:
             raise urllib2.URLError(err)
-
-        for args in self.parent.addheaders:
-            h.putheader(*args)
-        for k, v in req.headers.items():
+        for k, v in headers.items():
             h.putheader(k, v)
         h.endheaders()
         if req.has_data():