# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 2017-02-16 06:53:45
# Node ID d8d698bcdcd62646c0a6a7444764bb00b110e050
# Parent  d05fefbb5ab374d8050daac26d4b77325eb35d42

tinyproxy: use IPv6 if HGIPV6 is set to 1

This patch makes tinyproxy.py work in IPv6 mode if HGIPV6 is set to 1.

This will make test-http-proxy.t pass on IPv6 machines.

diff --git a/tests/tinyproxy.py b/tests/tinyproxy.py
--- a/tests/tinyproxy.py
+++ b/tests/tinyproxy.py
@@ -26,6 +26,11 @@ httpserver = util.httpserver
 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 @@ class ProxyHandler (httpserver.basehttpr
         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 @@ class ProxyHandler (httpserver.basehttpr
         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()