Clean IPv6 support
This commit is contained in:
@@ -85,18 +85,18 @@ class HTTPServer(server.HTTPServer):
|
||||
|
||||
# Maybe a Pylint bug, ``__init__`` calls ``server.HTTPServer.__init__``
|
||||
# pylint: disable=W0231
|
||||
def __init__(self, address, handler, bind_and_activate = True):
|
||||
def __init__(self, address, handler, bind_and_activate=True):
|
||||
"""Create server."""
|
||||
self.use_ipv6 = ':' in address[0]
|
||||
ipv6 = ":" in address[0]
|
||||
|
||||
if self.use_ipv6:
|
||||
if ipv6:
|
||||
self.address_family = socket.AF_INET6
|
||||
|
||||
# call superclass, but do NOT bind and activate, as we might change socketopts
|
||||
server.HTTPServer.__init__(self, address, handler, bind_and_activate = False)
|
||||
# Do not bind and activate, as we might change socketopts
|
||||
server.HTTPServer.__init__(self, address, handler, False)
|
||||
|
||||
if self.use_ipv6:
|
||||
# only allow IPv6 connections to the IPv6 socket
|
||||
if ipv6:
|
||||
# Only allow IPv6 connections to the IPv6 socket
|
||||
self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 1)
|
||||
|
||||
if bind_and_activate:
|
||||
@@ -111,7 +111,7 @@ class HTTPSServer(HTTPServer):
|
||||
"""HTTPS server."""
|
||||
PROTOCOL = "https"
|
||||
|
||||
def __init__(self, address, handler, bind_and_activate = True):
|
||||
def __init__(self, address, handler, bind_and_activate=True):
|
||||
"""Create server by wrapping HTTP socket in an SSL socket."""
|
||||
# Fails with Python 2.5, import if needed
|
||||
# pylint: disable=F0401
|
||||
@@ -120,7 +120,7 @@ class HTTPSServer(HTTPServer):
|
||||
|
||||
HTTPServer.__init__(self, address, handler, False)
|
||||
self.socket = ssl.wrap_socket(
|
||||
self.socket, # we can use this, it is not bound yet
|
||||
self.socket,
|
||||
server_side=True,
|
||||
certfile=config.get("server", "certificate"),
|
||||
keyfile=config.get("server", "key"),
|
||||
|
Reference in New Issue
Block a user