simple_server: Correctly pass health option

It was completely ignored. Also don't de-serialize options. Just parse
them directly in `__init__`. Less error-prone.
This commit is contained in:
Nirbheek Chauhan 2020-05-25 18:28:29 +00:00 committed by Matthew Waters
parent 180e1ce24c
commit 78df1ca74c

View file

@ -17,9 +17,10 @@ import argparse
import http import http
import concurrent import concurrent
class WebRTCSimpleServer(object): class WebRTCSimpleServer(object):
def __init__(self, addr, port, keepalive_timeout, disable_ssl, certpath, health_path=None): def __init__(self, options):
############### Global data ############### ############### Global data ###############
# Format: {uid: (Peer WebSocketServerProtocol, # Format: {uid: (Peer WebSocketServerProtocol,
@ -34,17 +35,18 @@ class WebRTCSimpleServer(object):
# Room dict with a set of peers in each room # Room dict with a set of peers in each room
self.rooms = dict() self.rooms = dict()
self.keepalive_timeout = keepalive_timeout # Options
self.addr = addr self.addr = options.addr
self.port = port self.port = options.port
self.disable_ssl = disable_ssl self.keepalive_timeout = options.keepalive_timeout
self.certpath = certpath self.cert_path = options.cert_path
self.health_path = health_path self.disable_ssl = options.disable_ssl
self.health_path = options.health
############### Helper functions ############### ############### Helper functions ###############
async def health_check(self, path, request_headers): async def health_check(self, path, request_headers):
if path == self.health_part: if path == self.health_path:
return http.HTTPStatus.OK, [], b"OK\n" return http.HTTPStatus.OK, [], b"OK\n"
return None return None
@ -280,7 +282,7 @@ def main():
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
r = WebRTCSimpleServer(options.addr, options.port, options.keepalive_timeout, options.disable_ssl, options.cert_path) r = WebRTCSimpleServer(options)
loop.run_until_complete (r.run()) loop.run_until_complete (r.run())
loop.run_forever () loop.run_forever ()