tests/tinyproxy.py
changeset 31005 d8d698bcdcd6
parent 29566 075146e85bb6
child 31571 b2a41a826d71
equal deleted inserted replaced
31004:d05fefbb5ab3 31005:d8d698bcdcd6
    23 from mercurial import util
    23 from mercurial import util
    24 
    24 
    25 httpserver = util.httpserver
    25 httpserver = util.httpserver
    26 urlparse = util.urlparse
    26 urlparse = util.urlparse
    27 socketserver = util.socketserver
    27 socketserver = util.socketserver
       
    28 
       
    29 if os.environ.get('HGIPV6', '0') == '1':
       
    30     family = socket.AF_INET6
       
    31 else:
       
    32     family = socket.AF_INET
    28 
    33 
    29 class ProxyHandler (httpserver.basehttprequesthandler):
    34 class ProxyHandler (httpserver.basehttprequesthandler):
    30     __base = httpserver.basehttprequesthandler
    35     __base = httpserver.basehttprequesthandler
    31     __base_handle = __base.handle
    36     __base_handle = __base.handle
    32 
    37 
    63             self.send_error(404, msg)
    68             self.send_error(404, msg)
    64             return 0
    69             return 0
    65         return 1
    70         return 1
    66 
    71 
    67     def do_CONNECT(self):
    72     def do_CONNECT(self):
    68         soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    73         soc = socket.socket(family, socket.SOCK_STREAM)
    69         try:
    74         try:
    70             if self._connect_to(self.path, soc):
    75             if self._connect_to(self.path, soc):
    71                 self.log_request(200)
    76                 self.log_request(200)
    72                 self.wfile.write(self.protocol_version +
    77                 self.wfile.write(self.protocol_version +
    73                                  " 200 Connection established\r\n")
    78                                  " 200 Connection established\r\n")
    83         (scm, netloc, path, params, query, fragment) = urlparse.urlparse(
    88         (scm, netloc, path, params, query, fragment) = urlparse.urlparse(
    84             self.path, 'http')
    89             self.path, 'http')
    85         if scm != 'http' or fragment or not netloc:
    90         if scm != 'http' or fragment or not netloc:
    86             self.send_error(400, "bad url %s" % self.path)
    91             self.send_error(400, "bad url %s" % self.path)
    87             return
    92             return
    88         soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    93         soc = socket.socket(family, socket.SOCK_STREAM)
    89         try:
    94         try:
    90             if self._connect_to(netloc, soc):
    95             if self._connect_to(netloc, soc):
    91                 self.log_request()
    96                 self.log_request()
    92                 soc.send("%s %s %s\r\n" % (
    97                 soc.send("%s %s %s\r\n" % (
    93                     self.command,
    98                     self.command,