From b60d0d112c940a2e9cc990b21a5e2d6946f3be80 Mon Sep 17 00:00:00 2001 From: Shane Perry Date: Wed, 31 Jul 2019 15:53:32 -0600 Subject: [PATCH] Added a basic health check endpoint to the server --- webrtc/signalling/simple-server.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webrtc/signalling/simple-server.py b/webrtc/signalling/simple-server.py index e46f748550..3cb3ce2c0b 100755 --- a/webrtc/signalling/simple-server.py +++ b/webrtc/signalling/simple-server.py @@ -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