Module

protocols.h1

HTTP/1.1 protocol handler — sans-I/O wrapper around h11.

Translates between raw bytes and typed ProtocolEvents. The worker feeds bytes in via receive_data() and reads serialized bytes out via send_response() and send_body().

All state is per-connection, per-request-cycle. No shared mutable state.

Classes

H1Protocol 9
HTTP/1.1 protocol handler backed by h11. Implements the ProtocolHandler contract. Each instance ma…

HTTP/1.1 protocol handler backed by h11.

Implements the ProtocolHandler contract. Each instance manages a single TCP connection through one or more request-response cycles (keep-alive).

Methods

their_state 0 Any
Current h11 client-side state (for diagnostics).
property
def their_state(self) -> Any
Returns
Any
our_state 0 Any
Current h11 server-side state (for diagnostics).
property
def our_state(self) -> Any
Returns
Any
client_is_waiting_for_100_continue 0 bool
True if the client sent Expect: 100-continue.
property
def client_is_waiting_for_100_continue(self) -> bool
Returns
bool
receive_data 1 list[ProtocolEvent]
Feed raw bytes from the socket, return parsed protocol events.
def receive_data(self, data: bytes) -> list[ProtocolEvent]
Parameters
Name Type Description
data

Raw bytes received from the network.

Returns
list[ProtocolEvent] List of protocol events parsed from the input.
send_response 2 bytes
Serialize a response status line and headers into bytes.
def send_response(self, status: int, headers: list[tuple[bytes, bytes]]) -> bytes
Parameters
Name Type Description
status

HTTP status code.

headers

Response headers as (name, value) byte pairs.

Returns
bytes Serialized HTTP/1.1 response head bytes.
send_body 2 bytes
Serialize a response body chunk into bytes.
def send_body(self, data: bytes, more: bool = False) -> bytes
Parameters
Name Type Description
data

Body bytes to send.

more

True if more body chunks will follow.

Default:False
Returns
bytes Serialized bytes to write to the socket.
start_new_cycle 0
Prepare for the next request on keep-alive connections.
def start_new_cycle(self) -> None
has_pending_data 0 bool
True if h11 has buffered data from a pipelined request. After ``start_new_cycl…
def has_pending_data(self) -> bool

True if h11 has buffered data from a pipelined request.

Afterstart_new_cycle(), h11 may still have unconsumed bytes from a previous read. Check this before doing another socket read to avoid blocking when data is already available.

Returns
bool
Internal Methods 1
__init__ 1
def __init__(self, *, max_incomplete_event_size: int | None = None) -> None
Parameters
Name Type Description
max_incomplete_event_size Default:None