diff --git a/daphne/server.py b/daphne/server.py index 7b05a55..c19f0db 100755 --- a/daphne/server.py +++ b/daphne/server.py @@ -185,6 +185,7 @@ def build_endpoint_description_strings( """ socket_descriptions = [] if host and port: + host = host.strip('[]').replace(':', '\:') socket_descriptions.append('tcp:port=%d:interface=%s' % (int(port), host)) elif any([host, port]): raise ValueError('TCP binding requires both port and host kwargs.') diff --git a/daphne/tests/test_endpoints.py b/daphne/tests/test_endpoints.py index dacc9d8..15a5c37 100644 --- a/daphne/tests/test_endpoints.py +++ b/daphne/tests/test_endpoints.py @@ -28,6 +28,16 @@ class TestEndpointDescriptions(TestCase): ['tcp:port=8000:interface=127.0.0.1'] ) + self.assertEqual( + build(port=8000, host='[200a::1]'), + ['tcp:port=8000:interface=200a\:\:1'] + ) + + self.assertEqual( + build(port=8000, host='200a::1'), + ['tcp:port=8000:interface=200a\:\:1'] + ) + # incomplete port/host kwargs raise errors self.assertRaises( ValueError, @@ -123,6 +133,14 @@ class TestCLIInterface(TestCase): '-b 10.0.0.1', ['tcp:port=8000:interface=10.0.0.1'] ) + self.checkCLI( + '-b 200a::1', + ['tcp:port=8000:interface=200a\:\:1'] + ) + self.checkCLI( + '-b [200a::1]', + ['tcp:port=8000:interface=200a\:\:1'] + ) self.checkCLI( '-p 8080 -b example.com', ['tcp:port=8080:interface=example.com']