changeset 3608:802da51cab5b

Use httpconnection even with proxies. This should give us HTTP keepalive when we talk to proxies and should allow us to stream a file in unbundle (instead of reading everything into a string). This should fix issue376.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Wed, 01 Nov 2006 14:53:11 -0300
parents f4c9bb4ad7b1
children a969e81631ce
files mercurial/httprepo.py
diffstat 1 files changed, 7 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/httprepo.py	Wed Nov 01 17:56:55 2006 +0100
+++ b/mercurial/httprepo.py	Wed Nov 01 14:53:11 2006 -0300
@@ -132,7 +132,7 @@
 
         proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy')
         # XXX proxyauthinfo = None
-        handler = httphandler()
+        handlers = [httphandler()]
 
         if proxyurl:
             # proxy can be proper url or host[:port]
@@ -164,7 +164,7 @@
                     proxyscheme, netlocunsplit(proxyhost, proxyport,
                                                proxyuser, proxypasswd or ''),
                     proxypath, proxyquery, proxyfrag))
-                handler = urllib2.ProxyHandler({scheme: proxyurl})
+                handlers.append(urllib2.ProxyHandler({scheme: proxyurl}))
                 ui.debug(_('proxying through http://%s:%s\n') %
                           (proxyhost, proxyport))
 
@@ -183,10 +183,9 @@
                      (user, passwd and '*' * len(passwd) or 'not set'))
             passmgr.add_password(None, host, user, passwd or '')
 
-        opener = urllib2.build_opener(
-            handler,
-            urllib2.HTTPBasicAuthHandler(passmgr),
-            urllib2.HTTPDigestAuthHandler(passmgr))
+        handlers.extend((urllib2.HTTPBasicAuthHandler(passmgr),
+                         urllib2.HTTPDigestAuthHandler(passmgr)))
+        opener = urllib2.build_opener(*handlers)
 
         # 1.0 here is the _protocol_ version
         opener.addheaders = [('User-agent', 'mercurial/proto-1.0')]
@@ -222,11 +221,8 @@
         cu = "%s%s" % (self._url, qs)
         try:
             if data:
-                if isinstance(data, file):
-                    # urllib2 needs string or buffer when using a proxy
-                    data.seek(0)
-                    data = data.read()
-                self.ui.debug(_("sending %d bytes\n") % len(data))
+                self.ui.debug(_("sending %s bytes\n") %
+                              headers.get('content-length', 'X'))
             resp = urllib2.urlopen(urllib2.Request(cu, data, headers))
         except urllib2.HTTPError, inst:
             if inst.code == 401: