Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/httprepo.py @ 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 | c141d07198b9 |
children | a969e81631ce |
comparison
equal
deleted
inserted
replaced
3607:f4c9bb4ad7b1 | 3608:802da51cab5b |
---|---|
130 urlpath, '', '')) | 130 urlpath, '', '')) |
131 self.ui = ui | 131 self.ui = ui |
132 | 132 |
133 proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy') | 133 proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy') |
134 # XXX proxyauthinfo = None | 134 # XXX proxyauthinfo = None |
135 handler = httphandler() | 135 handlers = [httphandler()] |
136 | 136 |
137 if proxyurl: | 137 if proxyurl: |
138 # proxy can be proper url or host[:port] | 138 # proxy can be proper url or host[:port] |
139 if not (proxyurl.startswith('http:') or | 139 if not (proxyurl.startswith('http:') or |
140 proxyurl.startswith('https:')): | 140 proxyurl.startswith('https:')): |
162 else: | 162 else: |
163 proxyurl = urlparse.urlunsplit(( | 163 proxyurl = urlparse.urlunsplit(( |
164 proxyscheme, netlocunsplit(proxyhost, proxyport, | 164 proxyscheme, netlocunsplit(proxyhost, proxyport, |
165 proxyuser, proxypasswd or ''), | 165 proxyuser, proxypasswd or ''), |
166 proxypath, proxyquery, proxyfrag)) | 166 proxypath, proxyquery, proxyfrag)) |
167 handler = urllib2.ProxyHandler({scheme: proxyurl}) | 167 handlers.append(urllib2.ProxyHandler({scheme: proxyurl})) |
168 ui.debug(_('proxying through http://%s:%s\n') % | 168 ui.debug(_('proxying through http://%s:%s\n') % |
169 (proxyhost, proxyport)) | 169 (proxyhost, proxyport)) |
170 | 170 |
171 # urllib2 takes proxy values from the environment and those | 171 # urllib2 takes proxy values from the environment and those |
172 # will take precedence if found, so drop them | 172 # will take precedence if found, so drop them |
181 if user: | 181 if user: |
182 ui.debug(_('http auth: user %s, password %s\n') % | 182 ui.debug(_('http auth: user %s, password %s\n') % |
183 (user, passwd and '*' * len(passwd) or 'not set')) | 183 (user, passwd and '*' * len(passwd) or 'not set')) |
184 passmgr.add_password(None, host, user, passwd or '') | 184 passmgr.add_password(None, host, user, passwd or '') |
185 | 185 |
186 opener = urllib2.build_opener( | 186 handlers.extend((urllib2.HTTPBasicAuthHandler(passmgr), |
187 handler, | 187 urllib2.HTTPDigestAuthHandler(passmgr))) |
188 urllib2.HTTPBasicAuthHandler(passmgr), | 188 opener = urllib2.build_opener(*handlers) |
189 urllib2.HTTPDigestAuthHandler(passmgr)) | |
190 | 189 |
191 # 1.0 here is the _protocol_ version | 190 # 1.0 here is the _protocol_ version |
192 opener.addheaders = [('User-agent', 'mercurial/proto-1.0')] | 191 opener.addheaders = [('User-agent', 'mercurial/proto-1.0')] |
193 urllib2.install_opener(opener) | 192 urllib2.install_opener(opener) |
194 | 193 |
220 q.update(args) | 219 q.update(args) |
221 qs = '?%s' % urllib.urlencode(q) | 220 qs = '?%s' % urllib.urlencode(q) |
222 cu = "%s%s" % (self._url, qs) | 221 cu = "%s%s" % (self._url, qs) |
223 try: | 222 try: |
224 if data: | 223 if data: |
225 if isinstance(data, file): | 224 self.ui.debug(_("sending %s bytes\n") % |
226 # urllib2 needs string or buffer when using a proxy | 225 headers.get('content-length', 'X')) |
227 data.seek(0) | |
228 data = data.read() | |
229 self.ui.debug(_("sending %d bytes\n") % len(data)) | |
230 resp = urllib2.urlopen(urllib2.Request(cu, data, headers)) | 226 resp = urllib2.urlopen(urllib2.Request(cu, data, headers)) |
231 except urllib2.HTTPError, inst: | 227 except urllib2.HTTPError, inst: |
232 if inst.code == 401: | 228 if inst.code == 401: |
233 raise util.Abort(_('authorization failed')) | 229 raise util.Abort(_('authorization failed')) |
234 raise | 230 raise |