tests/tinyproxy.py
changeset 31005 d8d698bcdcd6
parent 29566 075146e85bb6
child 31571 b2a41a826d71
--- a/tests/tinyproxy.py	Wed Feb 15 21:09:00 2017 -0800
+++ b/tests/tinyproxy.py	Wed Feb 15 22:53:45 2017 -0800
@@ -26,6 +26,11 @@
 urlparse = util.urlparse
 socketserver = util.socketserver
 
+if os.environ.get('HGIPV6', '0') == '1':
+    family = socket.AF_INET6
+else:
+    family = socket.AF_INET
+
 class ProxyHandler (httpserver.basehttprequesthandler):
     __base = httpserver.basehttprequesthandler
     __base_handle = __base.handle
@@ -65,7 +70,7 @@
         return 1
 
     def do_CONNECT(self):
-        soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        soc = socket.socket(family, socket.SOCK_STREAM)
         try:
             if self._connect_to(self.path, soc):
                 self.log_request(200)
@@ -85,7 +90,7 @@
         if scm != 'http' or fragment or not netloc:
             self.send_error(400, "bad url %s" % self.path)
             return
-        soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        soc = socket.socket(family, socket.SOCK_STREAM)
         try:
             if self._connect_to(netloc, soc):
                 self.log_request()