# HG changeset patch # User Benoit Boissinot # Date 1265917340 -3600 # Node ID 677f15da38c159366925976fe8e2b4861db89cd3 # Parent 1a8df80dfddefe8b45f61529bbe2f2615786a77b url: proxy handling, simplify and correctly deal with IPv6 Thanks to Henrik for testing. diff -r 1a8df80dfdde -r 677f15da38c1 mercurial/url.py --- a/mercurial/url.py Tue Feb 09 14:12:34 2010 -0600 +++ b/mercurial/url.py Thu Feb 11 20:42:20 2010 +0100 @@ -302,7 +302,7 @@ send = _gen_sendfile(keepalive.HTTPConnection) def connect(self): - if has_https and self.realhost: # use CONNECT proxy + if has_https and self.realhostport: # use CONNECT proxy self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.connect((self.host, self.port)) if _generic_proxytunnel(self): @@ -335,21 +335,16 @@ if new_tunnel or tunnel_host == req.get_full_url(): # has proxy urlparts = urlparse.urlparse(tunnel_host) if new_tunnel or urlparts[0] == 'https': # only use CONNECT for HTTPS - if ':' in urlparts[1]: - realhost, realport = urlparts[1].split(':') - realport = int(realport) - else: - realhost = urlparts[1] - realport = 443 + realhostport = urlparts[1] + if realhostport[-1] == ']' or ':' not in realhostport: + realhostport += ':443' - h.realhost = realhost - h.realport = realport + h.realhostport = realhostport h.headers = req.headers.copy() h.headers.update(handler.parent.addheaders) return - h.realhost = None - h.realport = None + h.realhostport = None h.headers = None def _generic_proxytunnel(self): @@ -357,7 +352,7 @@ [(x, self.headers[x]) for x in self.headers if x.lower().startswith('proxy-')]) self._set_hostport(self.host, self.port) - self.send('CONNECT %s:%d HTTP/1.0\r\n' % (self.realhost, self.realport)) + self.send('CONNECT %s HTTP/1.0\r\n' % self.realhostport) for header in proxyheaders.iteritems(): self.send('%s: %s\r\n' % header) self.send('\r\n') @@ -486,7 +481,7 @@ getresponse = keepalive.wrapgetresponse(httplib.HTTPSConnection) def connect(self): - if self.realhost: # use CONNECT proxy + if self.realhostport: # use CONNECT proxy self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.connect((self.host, self.port)) if _generic_proxytunnel(self):