#!/usr/bin/env python3 """Simple HTTP/3 client to test the server.""" import asyncio import logging from aioquic.asyncio import connect from aioquic.quic.configuration import QuicConfiguration logging.basicConfig(level=logging.DEBUG) async def test_http3(url: str): """Test HTTP/3 connection to the server.""" print(f"Testing HTTP/3 connection to: {url}") # Parse URL if url.startswith("https://"): url = url[8:] host, port = url.split(":") port = int(port.rstrip("/")) print(f"Connecting to {host}:{port}...") # Create QUIC configuration configuration = QuicConfiguration( is_client=True, alpn_protocols=["h3"], verify_mode=0 # Skip certificate verification for testing ) try: async with connect( host, port, configuration=configuration, ) as protocol: print(f"✓ QUIC connection established!") print(f" ALPN protocol: {protocol._quic.tls.alpn_negotiated}") print(f" Remote address: {protocol._quic.remote_address}") # Just test the connection, don't send HTTP requests yet await asyncio.sleep(1) print("✓ Connection successful!") return True except Exception as e: print(f"✗ Connection failed: {e}") import traceback traceback.print_exc() return False if __name__ == "__main__": import sys url = sys.argv[1] if len(sys.argv) > 1 else "https://127.0.0.1:4433" success = asyncio.run(test_http3(url)) sys.exit(0 if success else 1)