mirror of
https://github.com/django/daphne.git
synced 2024-11-22 16:06:34 +03:00
Fixed #90: X-Forwarded-For now does v6 address properly
It also now ignores ports, as I can't find a good example of them being put into the XFF header.
This commit is contained in:
parent
360a445f68
commit
c55bc8a94b
|
@ -31,13 +31,13 @@ class TestXForwardedForHttpParsing(TestCase):
|
||||||
['10.1.2.3', 0]
|
['10.1.2.3', 0]
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_port_in_address(self):
|
def test_v6_address(self):
|
||||||
headers = Headers({
|
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(
|
self.assertEqual(
|
||||||
parse_x_forwarded_for(headers),
|
parse_x_forwarded_for(headers),
|
||||||
['10.1.2.3', 5123]
|
['1043::a321:0001', 0]
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_multiple_proxys(self):
|
def test_multiple_proxys(self):
|
||||||
|
@ -85,13 +85,13 @@ class TestXForwardedForWsParsing(TestCase):
|
||||||
['10.1.2.3', 0]
|
['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(
|
self.assertEqual(
|
||||||
parse_x_forwarded_for(headers),
|
parse_x_forwarded_for(headers),
|
||||||
['10.1.2.3', 5123]
|
['1043::a321:0001', 0]
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_multiple_proxys(self):
|
def test_multiple_proxys(self):
|
||||||
|
|
|
@ -39,14 +39,6 @@ def parse_x_forwarded_for(headers,
|
||||||
if ',' in address_value:
|
if ',' in address_value:
|
||||||
address_value = address_value.split(",")[0].strip()
|
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:
|
if port_header_name:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user