"""serve.py MODE [PORT] h3 HTTP/1.1 + HTTP/2 on TCP (Hypercorn) and HTTP/3 on UDP (aioquic), same port number, Alt-Svc advertised h2 TCP only, ALPN h2 + http/1.1 h1 TCP only, ALPN http/1.1 """ import asyncio, os, sys mode = sys.argv[1]; port = sys.argv[2] if len(sys.argv) > 2 else "4433" if mode == "h3": os.environ["ALT_SVC_PORT"] = port from hypercorn.asyncio import serve from hypercorn.config import Config from app import app root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) c = Config() c.certfile, c.keyfile = f"{root}/certs/cert.pem", f"{root}/certs/key.pem" c.bind = [f"127.0.0.1:{port}"] c.loglevel = "WARNING" if mode == "h1": c.alpn_protocols = ["http/1.1"] elif mode not in ("h2", "h3"): sys.exit("mode must be h3, h2 or h1") async def main(): tasks = [serve(app, c)] if mode == "h3": import h3server tasks.append(h3server.start(int(port), c.certfile, c.keyfile)) await asyncio.gather(*tasks) asyncio.run(main())