Skip to main content

trillium_http/
h2.rs

1//! Trillium HTTP/2 types (RFC 9113).
2//!
3//! This module is the server-side HTTP/2 implementation used by `trillium-http`. Most items are
4//! crate-private; only the error types are part of the public surface.
5mod acceptor;
6mod body_wrapper;
7mod connection;
8mod error;
9mod frame;
10#[cfg(feature = "unstable")]
11mod initiator;
12mod role;
13mod settings;
14mod stream_state;
15mod transport;
16
17use crate::headers::compression_error::CompressionError;
18pub use acceptor::H2Driver;
19pub(crate) use body_wrapper::H2Body;
20pub use connection::H2Connection;
21#[cfg(feature = "unstable")]
22#[doc(hidden)]
23pub use connection::{ResponseHeaders, SubmitSend};
24pub use error::H2ErrorCode;
25#[cfg(feature = "unstable")]
26pub use initiator::H2Initiator;
27#[cfg(feature = "unstable")]
28pub use settings::H2Settings;
29#[cfg(not(feature = "unstable"))]
30pub(crate) use settings::H2Settings;
31pub use transport::H2Transport;
32
33/// An error that may occur during HTTP/2 stream or connection processing.
34///
35/// When the error is `Protocol`, the contained [`H2ErrorCode`] should be communicated to the peer
36/// via GOAWAY (for connection-level errors) or `RST_STREAM` (for stream-level errors); the
37/// distinction is contextual. `Io` errors indicate an unrecoverable transport failure.
38#[derive(thiserror::Error, Debug)]
39pub enum H2Error {
40    /// An HTTP/2 protocol error; the code should be signalled to the peer.
41    #[error(transparent)]
42    Protocol(#[from] H2ErrorCode),
43
44    /// An unrecoverable I/O error encountered at the network layer.
45    #[error(transparent)]
46    Io(#[from] std::io::Error),
47}
48
49/// HPACK decoding failures map to `COMPRESSION_ERROR`.
50impl From<CompressionError> for H2Error {
51    fn from(_: CompressionError) -> Self {
52        Self::Protocol(H2ErrorCode::CompressionError)
53    }
54}