Classes
_RequestMeta
1
▼
Pre-extracted header values from a single pass over request headers.
All fields populated by ``_cl…
_RequestMeta
1
▼
Pre-extracted header values from a single pass over request headers.
All fields populated by_classify_request()— avoids redundant
linear scans per request. Header names from_fast_h1are already
lowered, so no.lower()is needed on names.
Methods
Internal Methods 1 ▼
__init__
0
▼
__init__
0
▼
def __init__(self) -> None
SyncWorker
12
▼
Blocking I/O worker — one request at a time, no event loop.
On 3.14t, runs in a thread with true p…
SyncWorker
12
▼
Blocking I/O worker — one request at a time, no event loop.
On 3.14t, runs in a thread with true parallelism. Handles HTTP/1.1 keep-alive in a tight recv/send loop. Streaming and WebSocket require handoff to the async pool (Phase 2).
Methods
set_lifespan_state
1
▼
Set the lifespan state dict shared with all requests.
set_lifespan_state
1
▼
def set_lifespan_state(self, state: dict[str, Any]) -> None
Parameters
| Name | Type | Description |
|---|---|---|
state |
— |
start_draining
0
▼
Mark this worker as draining (stop accepting new connections).
start_draining
0
▼
def start_draining(self) -> None
is_idle
0
bool
▼
True if no connection is currently being handled.
is_idle
0
bool
▼
def is_idle(self) -> bool
Returns
bool
run
0
▼
Accept connections until shutdown (blocking).
run
0
▼
def run(self) -> None
Internal Methods 8 ▼
__init__
10
▼
__init__
10
▼
def __init__(self, config: ServerConfig, app: ASGIApp, sock: socket.socket | None, *, worker_id: int = 0, shutdown_event: threading.Event | None = None, ssl_context: ssl.SSLContext | None = None, lifecycle_collector: LifecycleCollector | None = None, async_pool: AsyncPool | None = None, conn_queue: queue.Queue[tuple[socket.socket, object]] | None = None, sync_app: SyncApp | None = None) -> None
Parameters
| Name | Type | Description |
|---|---|---|
config |
— |
|
app |
— |
|
sock |
— |
|
worker_id |
— |
Default:0
|
shutdown_event |
— |
Default:None
|
ssl_context |
— |
Default:None
|
lifecycle_collector |
— |
Default:None
|
async_pool |
— |
Default:None
|
conn_queue |
— |
Default:None
|
sync_app |
— |
Default:None
|
_run_from_queue
2
▼
Get connections from distributor queue (no thundering herd).
_run_from_queue
2
▼
def _run_from_queue(self, poll_interval: float, runner: asyncio.Runner) -> None
Parameters
| Name | Type | Description |
|---|---|---|
poll_interval |
— |
|
runner |
— |
_run_accept_loop
2
▼
Accept directly from socket (SO_REUSEPORT or single worker).
_run_accept_loop
2
▼
def _run_accept_loop(self, poll_interval: float, runner: asyncio.Runner) -> None
Parameters
| Name | Type | Description |
|---|---|---|
poll_interval |
— |
|
runner |
— |
_handle_connection
3
▼
Handle a single TCP connection through request-response cycles.
_handle_connection
3
▼
def _handle_connection(self, conn: socket.socket, addr: tuple[str, int], runner: asyncio.Runner) -> None
Parameters
| Name | Type | Description |
|---|---|---|
conn |
— |
|
addr |
— |
|
runner |
— |
_handle_connection_impl
3
bool
▼
Inner connection handling. Returns True if handed off to async pool.
_handle_connection_impl
3
bool
▼
def _handle_connection_impl(self, conn: socket.socket, addr: tuple[str, int], runner: asyncio.Runner) -> bool
Parameters
| Name | Type | Description |
|---|---|---|
conn |
— |
|
addr |
— |
|
runner |
— |
Returns
bool
_recv_request_fast
1
tuple[RequestReceived | …
▼
Read a complete HTTP request using the fast parser.
Accumulates data in the re…
_recv_request_fast
1
tuple[RequestReceived | …
▼
def _recv_request_fast(self, conn: socket.socket) -> tuple[RequestReceived | None, bytes]
Read a complete HTTP request using the fast parser.
Accumulates data in the recv buffer until a complete request (headers + body based on Content-Length) is available. Returns (request, body) or (None, b"") on connection close/error.
Parameters
| Name | Type | Description |
|---|---|---|
conn |
— |
Returns
tuple[RequestReceived | None, bytes]
_cached_date_header
0
bytes | None
▼
Return cached Date header bytes, refreshing at most once per second.
_cached_date_header
0
bytes | None
▼
def _cached_date_header(self) -> bytes | None
Returns
bytes | None
_send_error
3
▼
Send a plain-text error response (raw bytes, no h11).
_send_error
3
▼
def _send_error(self, conn: socket.socket, status: int, message: str) -> None
Parameters
| Name | Type | Description |
|---|---|---|
conn |
— |
|
status |
— |
|
message |
— |
Functions
_classify_request
1
_RequestMeta
▼
Single-pass header extraction for the sync-worker hot path.
Replaces separate …
_classify_request
1
_RequestMeta
▼
def _classify_request(request: RequestReceived) -> _RequestMeta
Single-pass header extraction for the sync-worker hot path.
Replaces separate calls to_wants_close, _is_websocket_upgrade,
andget_header(accept-encoding).
Header names are already lowered by_fast_h1.parse_request.
Parameters
| Name | Type | Description |
|---|---|---|
request |
RequestReceived |
Returns
_RequestMeta