MCPcopy
hub / github.com/benoitc/gunicorn / AsyncHTTP2Connection

Class AsyncHTTP2Connection

gunicorn/http2/async_connection.py:48–592  ·  view source on GitHub ↗

Async HTTP/2 server-side connection handler for ASGI. Manages the HTTP/2 connection state and multiplexed streams using asyncio for non-blocking I/O operations.

Source from the content-addressed store, hash-verified

46
47
48class AsyncHTTP2Connection:
49 """Async HTTP/2 server-side connection handler for ASGI.
50
51 Manages the HTTP/2 connection state and multiplexed streams
52 using asyncio for non-blocking I/O operations.
53 """
54
55 # Default buffer size for socket reads
56 READ_BUFFER_SIZE = 65536
57
58 def __init__(self, cfg, reader, writer, client_addr):
59 """Initialize an async HTTP/2 server connection.
60
61 Args:
62 cfg: Gunicorn configuration object
63 reader: asyncio StreamReader
64 writer: asyncio StreamWriter
65 client_addr: Client address tuple (host, port)
66
67 Raises:
68 HTTP2NotAvailable: If h2 library is not installed
69 """
70 _import_h2()
71
72 self.cfg = cfg
73 self.reader = reader
74 self.writer = writer
75 self.client_addr = client_addr
76
77 # Active streams indexed by stream ID
78 self.streams = {}
79
80 # Queue of completed requests for the worker
81 self._request_queue = asyncio.Queue()
82
83 # Connection settings from config
84 self.initial_window_size = cfg.http2_initial_window_size
85 self.max_concurrent_streams = cfg.http2_max_concurrent_streams
86 self.max_frame_size = cfg.http2_max_frame_size
87 self.max_header_list_size = cfg.http2_max_header_list_size
88
89 # Initialize h2 connection
90 config = _h2_config.H2Configuration(
91 client_side=False,
92 header_encoding='utf-8',
93 )
94 self.h2_conn = _h2.H2Connection(config=config)
95
96 # Connection state
97 self._closed = False
98 self._initialized = False
99 self._receive_task = None
100
101 async def initiate_connection(self):
102 """Send initial HTTP/2 settings to client.
103
104 Should be called after the SSL handshake completes and
105 before processing any data.

Calls

no outgoing calls