def __init__(self):
# HTTP server init
ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ssl_context.options |= (ssl.OP_NO_TLSv1 | ssl.OP_NO_TLSv1_1 | ssl.OP_NO_COMPRESSION)
ssl_context.load_cert_chain(certfile=config.CFG.http["SERVER_SSL_CERT"], keyfile=config.CFG.http["SERVER_SSL_PRIVKEY"])
if ssl.HAS_ALPN:
ssl_context.set_alpn_protocols(["h2"])
else:
info("Python not compiled with ALPN support, using NPN instead.")
ssl_context.set_npn_protocols(["h2"])
if not config.CFG.http["DBG_DISABLE_CERTS"]:
ssl_context.verify_mode = ssl.CERT_REQUIRED
ssl_context.load_verify_locations(cafile=config.CFG.http["CA_CERT"])
self.loop = asyncio.get_event_loop()
# Each client connection will create a new H2Protocol instance
listener = self.loop.create_server(
H2Protocol,
"127.0.0.1" if config.CFG.http["LISTEN_LOCALHOST_ONLY"] else "",
config.CFG.http["PORT"],
ssl=ssl_context
)
self.server = self.loop.run_until_complete(listener)
H2Protocol.LOOP = self.loop
# Register HTTP handlers
评论列表
文章目录