Module

protocols.h1_httptools

HTTP/1.1 protocol handler — C-accelerated backend via httptools.

Drop-in replacement forH1Protocolthat uses httptools (Node.js http-parser bindings) for parsing. Response serialization is hand-crafted since httptools only parses inbound data.

Install viapip install pounce[fast]to enable.

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

Classes

H1HttpToolsProtocol 11
HTTP/1.1 protocol handler backed by httptools (C-accelerated). Implements the same ``ProtocolHandl…

HTTP/1.1 protocol handler backed by httptools (C-accelerated).

Implements the sameProtocolHandler contract as H1Protocol. Uses httptools for parsing (much faster than h11) and hand-crafts response serialization in pure Python.

Methods

keep_alive 0 bool
True if the client wants to keep the connection alive.
property
def keep_alive(self) -> bool
Returns
bool
on_url 1
Called when the URL is parsed.
def on_url(self, url: bytes) -> None
Parameters
Name Type Description
url
on_header 2
Called for each header pair.
def on_header(self, name: bytes, value: bytes) -> None
Parameters
Name Type Description
name
value
on_headers_complete 0
Called when all headers have been parsed.
def on_headers_complete(self) -> None
on_body 1
Called for each chunk of body data.
def on_body(self, body: bytes) -> None
Parameters
Name Type Description
body
on_message_complete 0
Called when the full request has been parsed.
def on_message_complete(self) -> None
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. httptools only parses…
def send_response(self, status: int, headers: list[tuple[bytes, bytes]]) -> bytes

Serialize a response status line and headers into bytes.

httptools only parses — response serialization is hand-crafted for maximum speed (no library overhead, no intermediate objects).

DetectsTransfer-Encoding: chunkedin the response headers so thatsend_bodyproduces correct chunked framing.

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. When chunked transfer encoding is …
def send_body(self, data: bytes, more: bool = False) -> bytes

Serialize a response body chunk into bytes.

When chunked transfer encoding is active (detected from response headers), produces proper chunked framing with size lines and a zero-length terminator.

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
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

Functions

is_httptools_available 0 bool
Return True if httptools is installed.
def is_httptools_available() -> bool
Returns
bool