Skip to main content

eggfetch_http_connect/
error.rs

1//! Neutral protocol errors for HTTP/1 CONNECT wire framing.
2//!
3//! The errors describe only what went wrong on the wire. They carry no
4//! Eggfetch client policy (`TimeoutPhase`, retryability, route identity),
5//! no TLS state, and no downstream-consumer variants. Diagnostics are
6//! bounded: attacker-controlled response bytes and credential material are
7//! never echoed.
8
9use std::io;
10
11/// Neutral CONNECT wire error.
12///
13/// All variants are fail-closed protocol failures. Messages are fixed
14/// strings or bounded sizes; they never include raw credentials or
15/// unbounded proxy-controlled bytes.
16#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
17#[non_exhaustive]
18pub enum ConnectError {
19    /// CONNECT target host/port is invalid (empty, control bytes, bad brackets).
20    #[error("invalid CONNECT target")]
21    InvalidTarget,
22    /// A caller-supplied header name/value is invalid or unsafe.
23    #[error("invalid CONNECT header")]
24    InvalidHeader,
25    /// Proxy credentials are invalid (control characters, bad shape).
26    #[error("invalid proxy credentials")]
27    InvalidCredentials,
28    /// Duplicate `Proxy-Authorization` was supplied.
29    #[error("duplicate proxy-authorization header")]
30    DuplicateAuthorization,
31    /// A reserved header would override generated framing.
32    #[error("reserved CONNECT header")]
33    ReservedHeader,
34    /// Serialized request head exceeds the caller-provided bound.
35    #[error("CONNECT request head too large: {len} exceeds maximum {max}")]
36    RequestHeadTooLarge {
37        /// Observed serialized length in bytes.
38        len: usize,
39        /// Caller-provided maximum in bytes.
40        max: usize,
41    },
42    /// Underlying transport I/O failed.
43    #[error("CONNECT transport I/O failed: {0}")]
44    Io(String),
45    /// Status line is syntactically invalid.
46    #[error("malformed CONNECT status line")]
47    MalformedStatus,
48    /// A header line is syntactically invalid.
49    #[error("malformed CONNECT header line")]
50    MalformedHeader,
51    /// Status line exceeds the caller-provided bound.
52    #[error("CONNECT status line exceeds maximum of {max} bytes")]
53    StatusLineTooLarge {
54        /// Caller-provided maximum in bytes.
55        max: usize,
56    },
57    /// A header line exceeds the caller-provided bound.
58    #[error("CONNECT header line exceeds maximum of {max} bytes")]
59    HeaderLineTooLarge {
60        /// Caller-provided maximum in bytes.
61        max: usize,
62    },
63    /// Aggregate response head exceeds the caller-provided bound.
64    #[error("CONNECT response head exceeds maximum of {max} bytes")]
65    ResponseHeadTooLarge {
66        /// Caller-provided maximum in bytes.
67        max: usize,
68    },
69    /// Response carries more header fields than allowed.
70    #[error("too many CONNECT response headers: maximum {max}")]
71    TooManyHeaders {
72        /// Caller-provided maximum header count.
73        max: usize,
74    },
75    /// Stream ended before the response head completed.
76    #[error("unexpected EOF while reading CONNECT response head")]
77    UnexpectedEof,
78}
79
80impl From<io::Error> for ConnectError {
81    fn from(error: io::Error) -> Self {
82        // `io::Error` display strings are transport diagnostics, not
83        // proxy-controlled response bytes or credentials.
84        Self::Io(error.to_string())
85    }
86}