aboutsummaryrefslogtreecommitdiff
path: root/dummyserver
diff options
context:
space:
mode:
authorSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:19:43 -0700
committerSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:19:43 -0700
commite6838673bda9af1e9bf7c4f71b25cf3e3dfc1253 (patch)
tree9b3a790337eee838225caa031f8051123157e6f0 /dummyserver
parentc9df3d807f7134f58f4a84dc8b80e9dc98c62f3a (diff)
downloadpython-urllib3-e6838673bda9af1e9bf7c4f71b25cf3e3dfc1253.tar
python-urllib3-e6838673bda9af1e9bf7c4f71b25cf3e3dfc1253.tar.gz
Imported Upstream version 1.11
Diffstat (limited to 'dummyserver')
-rw-r--r--dummyserver/handlers.py11
-rwxr-xr-xdummyserver/server.py33
-rw-r--r--dummyserver/testcase.py14
3 files changed, 55 insertions, 3 deletions
diff --git a/dummyserver/handlers.py b/dummyserver/handlers.py
index 53fbe4a..ffa1dd3 100644
--- a/dummyserver/handlers.py
+++ b/dummyserver/handlers.py
@@ -73,6 +73,10 @@ class TestingApp(RequestHandler):
""" Handle OPTIONS requests """
self._call_method()
+ def head(self):
+ """ Handle HEAD requests """
+ self._call_method()
+
def _call_method(self):
""" Call the correct method in this class based on the incoming URI """
req = self.request
@@ -232,6 +236,13 @@ class TestingApp(RequestHandler):
return Response(chunks, headers=[('Content-Encoding', 'gzip')])
+ def nbytes(self, request):
+ length = int(request.params.get('length'))
+ data = b'1' * length
+ return Response(
+ data,
+ headers=[('Content-Type', 'application/octet-stream')])
+
def shutdown(self, request):
sys.exit()
diff --git a/dummyserver/server.py b/dummyserver/server.py
index 63124d3..1999474 100755
--- a/dummyserver/server.py
+++ b/dummyserver/server.py
@@ -38,6 +38,35 @@ DEFAULT_CA = os.path.join(CERTS_PATH, 'cacert.pem')
DEFAULT_CA_BAD = os.path.join(CERTS_PATH, 'client_bad.pem')
NO_SAN_CA = os.path.join(CERTS_PATH, 'cacert.no_san.pem')
+def _has_ipv6(host):
+ """ Returns True if the system can bind an IPv6 address. """
+ sock = None
+ has_ipv6 = False
+
+ if socket.has_ipv6:
+ # has_ipv6 returns true if cPython was compiled with IPv6 support.
+ # It does not tell us if the system has IPv6 support enabled. To
+ # determine that we must bind to an IPv6 address.
+ # https://github.com/shazow/urllib3/pull/611
+ # https://bugs.python.org/issue658327
+ try:
+ sock = socket.socket(socket.AF_INET6)
+ sock.bind((host, 0))
+ has_ipv6 = True
+ except:
+ pass
+
+ if sock:
+ sock.close()
+ return has_ipv6
+
+# Some systems may have IPv6 support but DNS may not be configured
+# properly. We can not count that localhost will resolve to ::1 on all
+# systems. See https://github.com/shazow/urllib3/pull/611 and
+# https://bugs.python.org/issue18792
+HAS_IPV6_AND_DNS = _has_ipv6('localhost')
+HAS_IPV6 = _has_ipv6('::1')
+
# Different types of servers we have:
@@ -64,7 +93,7 @@ class SocketServerThread(threading.Thread):
self.ready_event = ready_event
def _start_server(self):
- if socket.has_ipv6:
+ if HAS_IPV6_AND_DNS:
sock = socket.socket(socket.AF_INET6)
else:
warnings.warn("No IPv6 support. Falling back to IPv4.",
@@ -117,7 +146,7 @@ def bind_sockets(port, address=None, family=socket.AF_UNSPEC, backlog=128,
sockets = []
if address == "":
address = None
- if not socket.has_ipv6 and family == socket.AF_UNSPEC:
+ if not HAS_IPV6 and family == socket.AF_UNSPEC:
# Python can be compiled with --disable-ipv6, which causes
# operations on AF_INET6 sockets to fail, but does not
# automatically exclude those results from getaddrinfo
diff --git a/dummyserver/testcase.py b/dummyserver/testcase.py
index 67e62cf..de6aedd 100644
--- a/dummyserver/testcase.py
+++ b/dummyserver/testcase.py
@@ -14,7 +14,6 @@ from dummyserver.handlers import TestingApp
from dummyserver.proxy import ProxyHandler
-
class SocketDummyServerTestCase(unittest.TestCase):
"""
A simple socket-based server is created for this class that is good for
@@ -131,3 +130,16 @@ class IPv6HTTPDummyServerTestCase(HTTPDummyServerTestCase):
raise SkipTest('IPv6 not available')
else:
super(IPv6HTTPDummyServerTestCase, cls).setUpClass()
+
+
+class IPv6HTTPDummyProxyTestCase(HTTPDummyProxyTestCase):
+
+ http_host = 'localhost'
+ http_host_alt = '127.0.0.1'
+
+ https_host = 'localhost'
+ https_host_alt = '127.0.0.1'
+ https_certs = DEFAULT_CERTS
+
+ proxy_host = '::1'
+ proxy_host_alt = '127.0.0.1'