diff --git a/daphne/tests/test_utils.py b/daphne/tests/test_utils.py index c0f4b6d..e12322e 100644 --- a/daphne/tests/test_utils.py +++ b/daphne/tests/test_utils.py @@ -31,13 +31,13 @@ class TestXForwardedForHttpParsing(TestCase): ['10.1.2.3', 0] ) - def test_port_in_address(self): + def test_v6_address(self): headers = Headers({ - b'X-Forwarded-For': [b'10.1.2.3:5123'], + b'X-Forwarded-For': [b'1043::a321:0001, 10.0.5.6'], }) self.assertEqual( parse_x_forwarded_for(headers), - ['10.1.2.3', 5123] + ['1043::a321:0001', 0] ) def test_multiple_proxys(self): @@ -85,13 +85,13 @@ class TestXForwardedForWsParsing(TestCase): ['10.1.2.3', 0] ) - def test_port_in_address(self): + def test_v6_address(self): headers = { - b'X-Forwarded-For': b'10.1.2.3:5123', + b'X-Forwarded-For': [b'1043::a321:0001, 10.0.5.6'], } self.assertEqual( parse_x_forwarded_for(headers), - ['10.1.2.3', 5123] + ['1043::a321:0001', 0] ) def test_multiple_proxys(self): diff --git a/daphne/utils.py b/daphne/utils.py index 2f375ba..cb8043c 100644 --- a/daphne/utils.py +++ b/daphne/utils.py @@ -39,15 +39,7 @@ def parse_x_forwarded_for(headers, if ',' in address_value: address_value = address_value.split(",")[0].strip() - if ':' in address_value: - address_host, address_port = address_value.split(':') - result = [address_host, 0] - try: - result[1] = int(address_port) - except ValueError: - pass - else: - result = [address_value, 0] + result = [address_value, 0] if port_header_name: # We only want to parse the X-Forwarded-Port header if we also parsed the X-Forwarded-For