websockets: report hostname and connected time

By retreiving and storing the hostname in the websocket
header, it is possible to determine a fully qualified domain
used to reach the instance.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-03-04 14:20:06 -05:00
parent 221df0937d
commit b86e86aff2
No known key found for this signature in database
GPG Key ID: 7027245FBBDDF59A
1 changed files with 12 additions and 1 deletions

View File

@ -392,9 +392,19 @@ class WebSocket(WebSocketHandler, Subscribable):
self.queue_busy: bool = False
self.message_buf: List[Union[str, Dict[str, Any]]] = []
self.last_pong_time: float = self.event_loop.get_loop_time()
self._connected_time: float = 0.
@property
def hostname(self) -> str:
return self.request.host_name
@property
def start_time(self) -> float:
return self._connected_time
def open(self, *args, **kwargs) -> None:
self.set_nodelay(True)
self._connected_time = self.event_loop.get_loop_time()
agent = self.request.headers.get("User-Agent", "")
is_proxy = False
if (
@ -404,7 +414,8 @@ class WebSocket(WebSocketHandler, Subscribable):
is_proxy = True
logging.info(f"Websocket Opened: ID: {self.uid}, "
f"Proxied: {is_proxy}, "
f"User Agent: {agent}")
f"User Agent: {agent}, "
f"Host Name: {self.hostname}")
self.wsm.add_websocket(self)
def on_message(self, message: Union[bytes, str]) -> None: