rest_server.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:jetconf 作者: CZ-NIC 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号