Skip to main content

vibeio_http/h3/qpack/
error.rs

1//! QPACK error codes (RFC 9114 Section 8.1, reused by RFC 9204 Section 6).
2//!
3//! The QPACK error family is `0x02xx`: these codes are carried in
4//! CONNECTION_CLOSE frames by the HTTP/3 layer, which maps them here.
5
6/// Errors raised while QPACK state is inconsistent or a representation is
7/// malformed.
8///
9/// `DecompressionFailed` is produced by field section decoding, the other
10/// two by processing of the peer's respective QPACK stream. All three are
11/// fatal for the connection: there is no way to resynchronize.
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum QpackError {
14    /// `QPACK_DECOMPRESSION_FAILED` (0x0200): a field section could not be
15    /// decoded, or references an entry that is evicted or out of range, or
16    /// exceeds the advertised `SETTINGS_MAX_FIELD_SECTION_SIZE`.
17    DecompressionFailed,
18    /// `QPACK_ENCODER_STREAM_ERROR` (0x0201): an encoder stream instruction
19    /// was malformed or violated table constraints.
20    EncoderStream,
21    /// `QPACK_DECODER_STREAM_ERROR` (0x0202): a decoder stream instruction
22    /// was malformed. Kept so [`QpackError::code`] mirrors the full error
23    /// family; this implementation only *emits* decoder stream instructions,
24    /// it never parses them, so the variant is never constructed.
25    DecoderStream,
26}
27
28impl QpackError {
29    /// The HTTP/3 CONNECTION_CLOSE error code (RFC 9204 Section 6).
30    ///
31    /// Consumed by the HTTP/3 layer and by the error-module tests that
32    /// pin the `0x02xx` family against the `0x01xx` HTTP/3 family.
33    #[inline]
34    pub fn code(self) -> u16 {
35        match self {
36            QpackError::DecompressionFailed => 0x0200,
37            QpackError::EncoderStream => 0x0201,
38            QpackError::DecoderStream => 0x0202,
39        }
40    }
41}