changeset 14346:bf85c2639700

httpconnection: correctly handle redirects from http to https Previously the connection cache for keepalives didn't keep track of ssl. This meant that when we connected to an https server after that same server via http, both on the default port, we'd incorrectly reuse the non-https connection as the default port meant the connection cache key was the same.
author Augie Fackler <durin42@gmail.com>
date Mon, 16 May 2011 16:59:45 -0500
parents bf9a105aed0a
children e8debe1eb255
files mercurial/httpconnection.py
diffstat 1 files changed, 6 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/httpconnection.py	Sun May 15 21:33:51 2011 +0200
+++ b/mercurial/httpconnection.py	Mon May 16 16:59:45 2011 -0500
@@ -132,7 +132,7 @@
         self._connections = {}
 
     # shamelessly borrowed from urllib2.AbstractHTTPHandler
-    def do_open(self, http_class, req):
+    def do_open(self, http_class, req, use_ssl):
         """Return an addinfourl object for the request, using http_class.
 
         http_class must implement the HTTPConnection API from httplib.
@@ -173,7 +173,8 @@
         if not host:
             raise urllib2.URLError('no host given')
 
-        allconns = self._connections.get((host, proxy), [])
+        connkey = use_ssl, host, proxy
+        allconns = self._connections.get(connkey, [])
         conns = [c for c in allconns if not c.busy()]
         if conns:
             h = conns[0]
@@ -185,7 +186,7 @@
             if req.timeout is not socket._GLOBAL_DEFAULT_TIMEOUT:
                 timeout = req.timeout
             h = http_class(host, timeout=timeout, proxy_hostport=proxy)
-            self._connections.setdefault((host, proxy), []).append(h)
+            self._connections.setdefault(connkey, []).append(h)
 
         headers = dict(req.headers)
         headers.update(req.unredirected_hdrs)
@@ -217,7 +218,7 @@
     def http_open(self, req):
         if req.get_full_url().startswith('https'):
             return self.https_open(req)
-        return self.do_open(HTTPConnection, req)
+        return self.do_open(HTTPConnection, req, False)
 
     def https_open(self, req):
         res = readauthforuri(self.ui, req.get_full_url())
@@ -227,7 +228,7 @@
             self.ui.debug("using auth.%s.* for authentication\n" % group)
         else:
             self.auth = None
-        return self.do_open(self._makesslconnection, req)
+        return self.do_open(self._makesslconnection, req, True)
 
     def _makesslconnection(self, host, port=443, *args, **kwargs):
         keyfile = None