1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! The NetError type for net-core parsing failures.
/// Errors produced by the net-core parsing primitives.
///
/// These describe malformed or oversize wire data only. They carry no I/O or
/// application context; callers translate them into their own error domain.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum NetError {
/// The URL did not contain a `scheme://` separator, or was otherwise
/// structurally malformed (e.g. missing host).
MalformedUrl(String),
/// The URL scheme is not one this crate recognizes for default-port
/// resolution.
UnsupportedScheme(String),
/// The URL scheme did not match the scheme a caller required (via
/// [`parse_url_for_scheme`](crate::parse_url_for_scheme)).
UnexpectedScheme {
/// The scheme the caller required.
expected: String,
/// The scheme actually found in the URL.
found: String,
},
/// The URL port component could not be parsed as a `u16`.
InvalidPort(String),
/// The HTTP response head (status line + headers) was malformed.
InvalidHead(String),
/// A chunked-transfer size line was malformed.
InvalidChunkSize(String),
/// A chunked-transfer body ended before a complete chunk or trailer section.
TruncatedChunk,
/// A chunked-transfer chunk or trailer section used the wrong delimiter.
InvalidChunkDelimiter,
/// A length-prefixed or buffered payload exceeded the caller's size limit.
OversizeBody(usize),
/// A newline-delimited line exceeded the configured line size limit.
LineTooLong {
/// Maximum accepted line length in bytes.
max: usize,
},
}
impl core::fmt::Display for NetError {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::MalformedUrl(url) => write!(formatter, "malformed url {url}"),
Self::UnsupportedScheme(scheme) => write!(formatter, "unsupported url scheme {scheme}"),
Self::UnexpectedScheme { expected, found } => {
write!(formatter, "expected url scheme {expected}, found {found}")
}
Self::InvalidPort(url) => write!(formatter, "invalid port in url {url}"),
Self::InvalidHead(detail) => write!(formatter, "invalid http head: {detail}"),
Self::InvalidChunkSize(detail) => write!(formatter, "invalid chunk size: {detail}"),
Self::TruncatedChunk => write!(formatter, "truncated chunked body"),
Self::InvalidChunkDelimiter => write!(formatter, "invalid chunked body delimiter"),
Self::OversizeBody(limit) => {
write!(formatter, "payload exceeded size limit of {limit} bytes")
}
Self::LineTooLong { max } => {
write!(formatter, "line exceeded size limit of {max} bytes")
}
}
}
}
impl core::error::Error for NetError {}