HTTP/3 API¶
The HTTP/3 API performs no I/O on its own, leaving this to the API user. This allows you to integrate HTTP/3 in any Python application, regardless of the concurrency model you are using.
Connection¶
- class aioquic.h3.connection.H3Connection(quic, *, enable_webtransport=False)[source]¶
A low-level HTTP/3 connection object.
Warning
The
enable_webtransportoption is experimental, as WebTransport over HTTP/3 is still an Internet-Draft (draft-ietf-webtrans-http3). It could change or be removed in a future release.Deprecated since version 1.8.0: Passing
enable_webtransportas a positional argument is deprecated, pass it as a keyword argument instead.- Parameters:
quic (
QuicConnection) – AQuicConnectioninstance.enable_webtransport (
bool) – Whether to enable WebTransport.
- create_webtransport_stream(session_id, is_unidirectional=False)[source]¶
Create a WebTransport stream and return the stream ID.
Warning
This method is experimental, as WebTransport over HTTP/3 is still an Internet-Draft (draft-ietf-webtrans-http3). It could change or be removed in a future release.
Note
After calling this method you need to call the QUIC connection
datagrams_to_send()method to retrieve data which needs to be sent over the network. If you are using the asyncio API, calling thetransmit()method will do it for you.- Parameters:
- Raises:
InvalidStreamIdError – If the session ID is out of range.
InvalidStreamTypeError – If WebTransport is not enabled, or the session ID is not a client-initiated bidirectional stream.
- Return type:
- property quic_connection: QuicConnection¶
Return the QUIC connection this HTTP/3 connection runs on.
- send_data(stream_id, data, end_stream)[source]¶
Send data on the given stream.
Note
After calling this method you need to call the QUIC connection
datagrams_to_send()method to retrieve data which needs to be sent over the network. If you are using the asyncio API, calling thetransmit()method will do it for you.- Parameters:
- Raises:
InvalidStreamIdError – If the stream ID is out of range.
InvalidStreamTypeError – If the stream is not a request stream.
InvalidStreamStateError – If data is sent before the headers, after the trailers, or after the stream was ended or reset.
- Return type:
- send_datagram(stream_id, data)[source]¶
Send a datagram for the specified stream.
Note
After calling this method you need to call the QUIC connection
datagrams_to_send()method to retrieve data which needs to be sent over the network. If you are using the asyncio API, calling thetransmit()method will do it for you.- Parameters:
- Raises:
InvalidStreamIdError – If the stream ID is out of range.
InvalidStreamTypeError – If the stream is not a client-initiated bidirectional stream.
- Return type:
- send_headers(stream_id, headers, end_stream=False)[source]¶
Send headers on the given stream.
Note
After calling this method you need to call the QUIC connection
datagrams_to_send()method to retrieve data which needs to be sent over the network. If you are using the asyncio API, calling thetransmit()method will do it for you.- Parameters:
- Raises:
InvalidStreamIdError – If the stream ID is out of range.
InvalidStreamTypeError – If the stream is not a request stream.
InvalidStreamStateError – If headers are sent after the trailers, after the stream was ended or reset, or on a stream the peer has not opened, or an interim response would end the stream.
H3Error – If the peer stopped the QPACK encoder stream.
- Return type:
Events¶
- class aioquic.h3.events.DatagramReceived(data, stream_id)[source]¶
The DatagramReceived is fired whenever a datagram is received from the the remote peer.
- class aioquic.h3.events.DataReceived(data, stream_id, stream_ended)[source]¶
The DataReceived event is fired whenever data is received on a stream from the remote peer.
- class aioquic.h3.events.GoAwayReceived(stream_id)[source]¶
The GoAwayReceived event is fired when a client receives a GOAWAY frame, as the server starts shutting down the connection (RFC 9114 section 5.2).
The client MUST NOT initiate new requests on this connection. Requests on streams whose ID is
stream_idor higher were not processed by the server and can be retried on another connection. A server may send several GOAWAY frames, each with an ID no higher than the last.
- class aioquic.h3.events.HeadersReceived(headers, stream_id, stream_ended)[source]¶
The HeadersReceived event is fired whenever headers are received.
- class aioquic.h3.events.WebTransportStreamDataReceived(data, stream_id, stream_ended, session_id)[source]¶
The WebTransportStreamDataReceived is fired whenever data is received for a WebTransport stream.
Warning
This event is experimental, as WebTransport over HTTP/3 is still an Internet-Draft (draft-ietf-webtrans-http3). It could change or be removed in a future release.
Exceptions¶
- class aioquic.h3.exceptions.InvalidStreamIdError[source]¶
A stream ID was passed which is outside the range QUIC allows, from 0 to 2^62 - 1.