mirror of
https://github.com/django/daphne.git
synced 2024-11-22 16:06:34 +03:00
Fixed #8: UNIX sockets now don't try and send client/server info
This commit is contained in:
parent
ad8511e144
commit
c863e2f378
|
@ -103,6 +103,13 @@ class WebRequest(http.Request):
|
||||||
self.clean_headers.append((name.lower(), value))
|
self.clean_headers.append((name.lower(), value))
|
||||||
logger.debug("HTTP %s request for %s", self.method, self.reply_channel)
|
logger.debug("HTTP %s request for %s", self.method, self.reply_channel)
|
||||||
self.content.seek(0, 0)
|
self.content.seek(0, 0)
|
||||||
|
# Get client address if possible
|
||||||
|
if hasattr(self.client, "host") and hasattr(self.client, "port"):
|
||||||
|
self.client_addr = [self.client.host, self.client.port]
|
||||||
|
self.server_addr = [self.host.host, self.host.port]
|
||||||
|
else:
|
||||||
|
self.client_addr = None
|
||||||
|
self.server_addr = None
|
||||||
# Send message
|
# Send message
|
||||||
self.factory.channel_layer.send("http.request", {
|
self.factory.channel_layer.send("http.request", {
|
||||||
"reply_channel": self.reply_channel,
|
"reply_channel": self.reply_channel,
|
||||||
|
@ -114,8 +121,8 @@ class WebRequest(http.Request):
|
||||||
"query_string": self.unquote(self.query_string),
|
"query_string": self.unquote(self.query_string),
|
||||||
"headers": self.clean_headers,
|
"headers": self.clean_headers,
|
||||||
"body": self.content.read(),
|
"body": self.content.read(),
|
||||||
"client": [self.client.host, self.client.port],
|
"client": self.client_addr,
|
||||||
"server": [self.host.host, self.host.port],
|
"server": self.server_addr,
|
||||||
})
|
})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -185,7 +192,7 @@ class WebRequest(http.Request):
|
||||||
"path": self.path.decode("ascii"),
|
"path": self.path.decode("ascii"),
|
||||||
"status": self.code,
|
"status": self.code,
|
||||||
"method": self.method.decode("ascii"),
|
"method": self.method.decode("ascii"),
|
||||||
"client": "%s:%s" % (self.client.host, self.client.port),
|
"client": "%s:%s" % tuple(self.client_addr) if self.client_addr else None,
|
||||||
"time_taken": self.duration(),
|
"time_taken": self.duration(),
|
||||||
"size": self.sentLength,
|
"size": self.sentLength,
|
||||||
})
|
})
|
||||||
|
|
|
@ -41,14 +41,21 @@ class WebSocketProtocol(WebSocketServerProtocol):
|
||||||
self.reply_channel = self.channel_layer.new_channel("websocket.send!")
|
self.reply_channel = self.channel_layer.new_channel("websocket.send!")
|
||||||
# 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
|
||||||
|
if hasattr(self.transport.getPeer(), "host") and hasattr(self.transport.getPeer(), "port"):
|
||||||
|
self.client_addr = [self.transport.getPeer().host, self.transport.getPeer().port]
|
||||||
|
self.server_addr = [self.transport.getHost().host, self.transport.getHost().port]
|
||||||
|
else:
|
||||||
|
self.client_addr = None
|
||||||
|
self.server_addr = None
|
||||||
# Make initial request info dict from request (we only have it here)
|
# Make initial request info dict from request (we only have it here)
|
||||||
self.path = request.path.encode("ascii")
|
self.path = request.path.encode("ascii")
|
||||||
self.request_info = {
|
self.request_info = {
|
||||||
"path": self.unquote(self.path),
|
"path": self.unquote(self.path),
|
||||||
"headers": clean_headers,
|
"headers": clean_headers,
|
||||||
"query_string": self.unquote(query_string),
|
"query_string": self.unquote(query_string),
|
||||||
"client": [self.transport.getPeer().host, self.transport.getPeer().port],
|
"client": self.client_addr,
|
||||||
"server": [self.transport.getHost().host, self.transport.getHost().port],
|
"server": self.server_addr,
|
||||||
"reply_channel": self.reply_channel,
|
"reply_channel": self.reply_channel,
|
||||||
"order": 0,
|
"order": 0,
|
||||||
}
|
}
|
||||||
|
@ -78,7 +85,7 @@ class WebSocketProtocol(WebSocketServerProtocol):
|
||||||
self.channel_layer.send("websocket.connect", self.request_info)
|
self.channel_layer.send("websocket.connect", self.request_info)
|
||||||
self.factory.log_action("websocket", "connected", {
|
self.factory.log_action("websocket", "connected", {
|
||||||
"path": self.request.path,
|
"path": self.request.path,
|
||||||
"client": "%s:%s" % (self.transport.getPeer().host, self.transport.getPeer().port),
|
"client": "%s:%s" % tuple(self.client_addr) if self.client_addr else None,
|
||||||
})
|
})
|
||||||
|
|
||||||
def onMessage(self, payload, isBinary):
|
def onMessage(self, payload, isBinary):
|
||||||
|
@ -128,7 +135,7 @@ class WebSocketProtocol(WebSocketServerProtocol):
|
||||||
})
|
})
|
||||||
self.factory.log_action("websocket", "disconnected", {
|
self.factory.log_action("websocket", "disconnected", {
|
||||||
"path": self.request.path,
|
"path": self.request.path,
|
||||||
"client": "%s:%s" % (self.transport.getPeer().host, self.transport.getPeer().port),
|
"client": "%s:%s" % tuple(self.client_addr) if self.client_addr else None,
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
logger.debug("WebSocket closed before handshake established")
|
logger.debug("WebSocket closed before handshake established")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user