Transport Layer — Aquilia Documentation
Comprehensive guide and documentation for Transport Layer in the Aquilia framework. View API reference, examples, and implementation patterns.
HTTP Client / Internals Transport Layer The NativeTransport implements HTTP/1.1 protocol handling using pure Python asyncio — no external HTTP client dependencies. Architecture The transport layer is the foundation of Aquilia's HTTP client: HTTPClient ↓ Uses Session ↓ Uses NativeTransport ├─ ConnectionPool (connection reuse) ├─ HTTP/1.1 protocol implementation ├─ Chunked transfer encoding ├─ Gzip/deflate decompression ├─ SSL/TLS handling └─ Fault conversion Why Native Transport? Zero External Dependencies Built entirely on Python's standard library (asyncio, ssl, gzip, zlib). No need for aiohttp, httpx, or other third-party HTTP clients. Deep Integration Tight coupling with Aquilia's fault system. Network errors are automatically converted to typed faults (ConnectionFault, TimeoutFault, TLSFault) with structured metadata. HTTP/1.1 Protocol NativeTransport implements the HTTP/1.1 specification: • Persistent connections — Keep-alive for connection reuse. • Chunked encoding — Streaming without Content-Length headers. # Request format (what NativeTransport sends) GET /api/users HTTP/1.1\r Host: api.example.com\r User-Agent: Aquilia-HTTP/1.0\r Connection: keep-alive\r \r # Response format (what NativeTransport receives) HTTP/1.1 200 OK\r Content-Type: application/json\r Content-Length: 42\r Connection: keep-alive\r \r Connection Pooling # Internal structure (simplified) class ConnectionPool: def __init__(self, max_connections: int, keepalive_expiry: float): self._pool: dict[str, list[ConnectionInfo]] = self._max_connections = max_connections self._keepalive_expiry = keepalive_expiry async def acquire( self, scheme: str, host: str, port: int, ssl_context: ssl.SSLContext | None, ) -> tuple[StreamReader, StreamWriter]: key = f" :// : " # Try pool first if key in self._pool: for conn in self._pool[key]: if self._is_alive(conn): return conn.reader, conn.writer # Create new connection reader, writer = await asyncio.open_connection( host, port, ssl=ssl_context ) return reader, writer SSL/TLS Handling HTTPS connections are managed via Python's native ssl context: import ssl # Create SSL context from config if config.verify_ssl: ssl_context = ssl.create_default_context() else: ssl_context = ssl._create_unverified_context() # Connect with TLS reader, writer = await asyncio.open_connection( host, port, ssl=ssl_context, server_hostname=host, ) Performance Connection Reuse Keep-alive sockets avoid TCP handshake (~100ms) and TLS negotiation (~200ms) on repeat requests. Memory Efficiency Streaming response chunks prevents loading large file payloads fully into Python process memory. Sessions Advanced Usage )
Go to Homepage