Added a basic health check endpoint to the server

This commit is contained in:
Shane Perry 2019-07-31 15:53:32 -06:00 committed by Nirbheek Chauhan
parent 7fe9f8e092
commit b60d0d112c

View file

@ -14,6 +14,7 @@ import logging
import asyncio
import websockets
import argparse
import http
from concurrent.futures._base import TimeoutError
@ -46,6 +47,10 @@ rooms = dict()
############### Helper functions ###############
async def health_check(path, request_headers):
if path == "/health/":
return http.HTTPStatus.OK, [], b"OK\n"
async def recv_msg_ping(ws, raddr):
'''
Wait for a message forever, and send a regular ping to prevent bad routers
@ -265,7 +270,7 @@ if not options.disable_ssl:
print("Listening on https://{}:{}".format(*ADDR_PORT))
# Websocket server
wsd = websockets.serve(handler, *ADDR_PORT, ssl=sslctx,
wsd = websockets.serve(handler, *ADDR_PORT, ssl=sslctx, process_request=health_check,
# Maximum number of messages that websockets will pop
# off the asyncio and OS buffers per connection. See:
# https://websockets.readthedocs.io/en/stable/api.html#websockets.protocol.WebSocketCommonProtocol