Classes
H1HttpToolsProtocol
11
▼
HTTP/1.1 protocol handler backed by httptools (C-accelerated).
Implements the same ``ProtocolHandl…
H1HttpToolsProtocol
11
▼
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
keep_alive
0
bool
▼
def keep_alive(self) -> bool
Returns
bool
on_url
1
▼
Called when the URL is parsed.
on_url
1
▼
def on_url(self, url: bytes) -> None
Parameters
| Name | Type | Description |
|---|---|---|
url |
— |
on_header
2
▼
Called for each header pair.
on_header
2
▼
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.
on_headers_complete
0
▼
def on_headers_complete(self) -> None
on_body
1
▼
Called for each chunk of body data.
on_body
1
▼
def on_body(self, body: bytes) -> None
Parameters
| Name | Type | Description |
|---|---|---|
body |
— |
on_message_complete
0
▼
Called when the full request has been parsed.
on_message_complete
0
▼
def on_message_complete(self) -> None
receive_data
1
list[ProtocolEvent]
▼
Feed raw bytes from the socket, return parsed protocol events.
receive_data
1
list[ProtocolEvent]
▼
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…
send_response
2
bytes
▼
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 …
send_body
2
bytes
▼
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.
start_new_cycle
0
▼
def start_new_cycle(self) -> None
Internal Methods 1 ▼
__init__
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.
is_httptools_available
0
bool
▼
def is_httptools_available() -> bool
Returns
bool