mirror of
https://github.com/django/daphne.git
synced 2025-07-30 00:49:44 +03:00
Python 2 fix for host address
This is a copy of
57051a48cd
for the Websocket protocol.
In Python 2, Twisted returns a byte string for the host address, while
the spec requires a unicode string. A simple cast gives us consistency.
This commit is contained in:
parent
bd03fabce6
commit
66cbc50124
|
@ -50,9 +50,11 @@ class WebSocketProtocol(WebSocketServerProtocol):
|
||||||
# Tell main factory about it
|
# Tell main factory about it
|
||||||
self.main_factory.reply_protocols[self.reply_channel] = self
|
self.main_factory.reply_protocols[self.reply_channel] = self
|
||||||
# Get client address if possible
|
# Get client address if possible
|
||||||
if hasattr(self.transport.getPeer(), "host") and hasattr(self.transport.getPeer(), "port"):
|
peer = self.transport.getPeer()
|
||||||
self.client_addr = [self.transport.getPeer().host, self.transport.getPeer().port]
|
host = self.transport.getHost()
|
||||||
self.server_addr = [self.transport.getHost().host, self.transport.getHost().port]
|
if hasattr(peer, "host") and hasattr(peer, "port"):
|
||||||
|
self.client_addr = [six.text_type(peer.host), peer.port]
|
||||||
|
self.server_addr = [six.text_type(host.host), host.port]
|
||||||
else:
|
else:
|
||||||
self.client_addr = None
|
self.client_addr = None
|
||||||
self.server_addr = None
|
self.server_addr = None
|
||||||
|
|
Loading…
Reference in New Issue
Block a user