mercurial/url.py
changeset 10415 677f15da38c1
parent 10411 af4c42ec19ed
child 10482 95265afff99f
equal deleted inserted replaced
10414:1a8df80dfdde 10415:677f15da38c1
   300 class httpconnection(keepalive.HTTPConnection):
   300 class httpconnection(keepalive.HTTPConnection):
   301     # must be able to send big bundle as stream.
   301     # must be able to send big bundle as stream.
   302     send = _gen_sendfile(keepalive.HTTPConnection)
   302     send = _gen_sendfile(keepalive.HTTPConnection)
   303 
   303 
   304     def connect(self):
   304     def connect(self):
   305         if has_https and self.realhost: # use CONNECT proxy
   305         if has_https and self.realhostport: # use CONNECT proxy
   306             self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   306             self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   307             self.sock.connect((self.host, self.port))
   307             self.sock.connect((self.host, self.port))
   308             if _generic_proxytunnel(self):
   308             if _generic_proxytunnel(self):
   309                 # we do not support client x509 certificates
   309                 # we do not support client x509 certificates
   310                 self.sock = _ssl_wrap_socket(self.sock, None, None)
   310                 self.sock = _ssl_wrap_socket(self.sock, None, None)
   333         new_tunnel = False
   333         new_tunnel = False
   334 
   334 
   335     if new_tunnel or tunnel_host == req.get_full_url(): # has proxy
   335     if new_tunnel or tunnel_host == req.get_full_url(): # has proxy
   336         urlparts = urlparse.urlparse(tunnel_host)
   336         urlparts = urlparse.urlparse(tunnel_host)
   337         if new_tunnel or urlparts[0] == 'https': # only use CONNECT for HTTPS
   337         if new_tunnel or urlparts[0] == 'https': # only use CONNECT for HTTPS
   338             if ':' in urlparts[1]:
   338             realhostport = urlparts[1]
   339                 realhost, realport = urlparts[1].split(':')
   339             if realhostport[-1] == ']' or ':' not in realhostport:
   340                 realport = int(realport)
   340                 realhostport += ':443'
   341             else:
   341 
   342                 realhost = urlparts[1]
   342             h.realhostport = realhostport
   343                 realport = 443
       
   344 
       
   345             h.realhost = realhost
       
   346             h.realport = realport
       
   347             h.headers = req.headers.copy()
   343             h.headers = req.headers.copy()
   348             h.headers.update(handler.parent.addheaders)
   344             h.headers.update(handler.parent.addheaders)
   349             return
   345             return
   350 
   346 
   351     h.realhost = None
   347     h.realhostport = None
   352     h.realport = None
       
   353     h.headers = None
   348     h.headers = None
   354 
   349 
   355 def _generic_proxytunnel(self):
   350 def _generic_proxytunnel(self):
   356     proxyheaders = dict(
   351     proxyheaders = dict(
   357             [(x, self.headers[x]) for x in self.headers
   352             [(x, self.headers[x]) for x in self.headers
   358              if x.lower().startswith('proxy-')])
   353              if x.lower().startswith('proxy-')])
   359     self._set_hostport(self.host, self.port)
   354     self._set_hostport(self.host, self.port)
   360     self.send('CONNECT %s:%d HTTP/1.0\r\n' % (self.realhost, self.realport))
   355     self.send('CONNECT %s HTTP/1.0\r\n' % self.realhostport)
   361     for header in proxyheaders.iteritems():
   356     for header in proxyheaders.iteritems():
   362         self.send('%s: %s\r\n' % header)
   357         self.send('%s: %s\r\n' % header)
   363     self.send('\r\n')
   358     self.send('\r\n')
   364 
   359 
   365     # majority of the following code is duplicated from
   360     # majority of the following code is duplicated from
   484         # must be able to send big bundle as stream.
   479         # must be able to send big bundle as stream.
   485         send = _gen_sendfile(BetterHTTPS)
   480         send = _gen_sendfile(BetterHTTPS)
   486         getresponse = keepalive.wrapgetresponse(httplib.HTTPSConnection)
   481         getresponse = keepalive.wrapgetresponse(httplib.HTTPSConnection)
   487 
   482 
   488         def connect(self):
   483         def connect(self):
   489             if self.realhost: # use CONNECT proxy
   484             if self.realhostport: # use CONNECT proxy
   490                 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   485                 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
   491                 self.sock.connect((self.host, self.port))
   486                 self.sock.connect((self.host, self.port))
   492                 if _generic_proxytunnel(self):
   487                 if _generic_proxytunnel(self):
   493                     self.sock = _ssl_wrap_socket(self.sock, self.cert_file,
   488                     self.sock = _ssl_wrap_socket(self.sock, self.cert_file,
   494                                                  self.key_file)
   489                                                  self.key_file)