mirror of
https://github.com/django/daphne.git
synced 2024-11-21 23:46:33 +03:00
Fixed #207: Do header transforms for WebSocket XFF right
This commit is contained in:
parent
9f7e19cf2d
commit
84466d4ae4
|
@ -50,7 +50,7 @@ class WebSocketProtocol(WebSocketServerProtocol):
|
||||||
|
|
||||||
if self.server.proxy_forwarded_address_header:
|
if self.server.proxy_forwarded_address_header:
|
||||||
self.client_addr = parse_x_forwarded_for(
|
self.client_addr = parse_x_forwarded_for(
|
||||||
self.clean_headers,
|
dict(self.clean_headers),
|
||||||
self.server.proxy_forwarded_address_header,
|
self.server.proxy_forwarded_address_header,
|
||||||
self.server.proxy_forwarded_port_header,
|
self.server.proxy_forwarded_port_header,
|
||||||
self.client_addr
|
self.client_addr
|
||||||
|
|
|
@ -147,6 +147,27 @@ class TestWebsocket(DaphneTestCase):
|
||||||
self.assert_valid_websocket_scope(scope, subprotocols=subprotocols)
|
self.assert_valid_websocket_scope(scope, subprotocols=subprotocols)
|
||||||
self.assert_valid_websocket_connect_message(messages[0])
|
self.assert_valid_websocket_connect_message(messages[0])
|
||||||
|
|
||||||
|
def test_xff(self):
|
||||||
|
"""
|
||||||
|
Tests that X-Forwarded-For headers get parsed right
|
||||||
|
"""
|
||||||
|
headers = [
|
||||||
|
["X-Forwarded-For", "10.1.2.3"],
|
||||||
|
["X-Forwarded-Port", "80"],
|
||||||
|
]
|
||||||
|
with DaphneTestingInstance(xff=True) as test_app:
|
||||||
|
test_app.add_send_messages([
|
||||||
|
{
|
||||||
|
"type": "websocket.accept",
|
||||||
|
}
|
||||||
|
])
|
||||||
|
self.websocket_handshake(test_app, headers=headers)
|
||||||
|
# Validate the scope and messages we got
|
||||||
|
scope, messages = test_app.get_received()
|
||||||
|
self.assert_valid_websocket_scope(scope)
|
||||||
|
self.assert_valid_websocket_connect_message(messages[0])
|
||||||
|
assert scope["client"] == ["10.1.2.3", 80]
|
||||||
|
|
||||||
@given(
|
@given(
|
||||||
request_path=http_strategies.http_path(),
|
request_path=http_strategies.http_path(),
|
||||||
request_params=http_strategies.query_params(),
|
request_params=http_strategies.query_params(),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user