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 currently 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 transport;
15
16use crate::headers::compression_error::CompressionError;
17pub use acceptor::H2Driver;
18pub(crate) use body_wrapper::H2Body;
19pub use connection::H2Connection;
20#[cfg(feature = "unstable")]
21#[doc(hidden)]
22pub use connection::{ResponseHeaders, SubmitSend};
23pub use error::H2ErrorCode;
24#[cfg(feature = "unstable")]
25pub use initiator::H2Initiator;
26#[cfg(feature = "unstable")]
27pub use settings::H2Settings;
28#[cfg(not(feature = "unstable"))]
29pub(crate) use settings::H2Settings;
30pub use transport::H2Transport;
31
32/// An error that may occur during HTTP/2 stream or connection processing.
33///
34/// When the error is `Protocol`, the contained [`H2ErrorCode`] should be communicated to the peer
35/// via GOAWAY (for connection-level errors) or `RST_STREAM` (for stream-level errors); the
36/// distinction is contextual. `Io` errors indicate an unrecoverable transport failure.
37#[derive(thiserror::Error, Debug)]
38pub enum H2Error {
39    /// An HTTP/2 protocol error; the code should be signalled to the peer.
40    #[error(transparent)]
41    Protocol(#[from] H2ErrorCode),
42
43    /// An unrecoverable I/O error encountered at the network layer.
44    #[error(transparent)]
45    Io(#[from] std::io::Error),
46}
47
48/// HPACK decoding failures map to `COMPRESSION_ERROR` per RFC 9113 ยง4.3.1.
49impl From<CompressionError> for H2Error {
50    fn from(_: CompressionError) -> Self {
51        Self::Protocol(H2ErrorCode::CompressionError)
52    }
53}