HTTP/3 API¶
H3Connection translates between QUIC events and HTTP/3 events. It relies on a
QuicConnection for transport and performs no I/O itself.
from qh3 import H3Connection, quic_events
h3 = H3Connection(quic)
while (event := quic.next_event()) is not None:
for http_event in h3.handle_event(event):
handle_http_event(http_event)
stream_id = quic.get_next_available_stream_id()
h3.send_headers(
stream_id,
[
(b":method", b"GET"),
(b":scheme", b"https"),
(b":authority", b"example.com"),
(b":path", b"/"),
],
end_stream=True,
)
H3Connection
¶
A low-level HTTP/3 connection object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quic
|
QuicConnection
|
A :class: |
required |
create_webtransport_stream
¶
handle_event
¶
Handle a QUIC event and return a list of HTTP events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
QuicEvent
|
The QUIC event to handle. |
required |
send_datagram
¶
send_push_promise
¶
Send a push promise related to the specified stream.
Returns the stream ID on which headers and data can be sent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream_id
|
int
|
The stream ID on which to send the data. |
required |
headers
|
Headers
|
The HTTP request headers for this push. |
required |
send_data
¶
Send data on the given stream.
To retrieve datagram which need to be sent over the network call the QUIC
connection's :meth:~qh3.connection.QuicConnection.datagrams_to_send
method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream_id
|
int
|
The stream ID on which to send the data. |
required |
data
|
bytes
|
The data to send. |
required |
end_stream
|
bool
|
Whether to end the stream. |
required |
send_headers
¶
Send headers on the given stream.
To retrieve datagram which need to be sent over the network call the QUIC
connection's :meth:~qh3.connection.QuicConnection.datagrams_to_send
method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stream_id
|
int
|
The stream ID on which to send the headers. |
required |
headers
|
Headers
|
The HTTP headers to send. |
required |
end_stream
|
bool
|
Whether to end the stream. |
False
|
Exceptions¶
HTTP/3 parser exceptions and wire-level constants are implementation details.
Protocol errors encountered by handle_event() close the QUIC connection and
are not raised to the application.