1use std::str::Utf8Error;
2
3use http_types::url;
4use thiserror::Error;
5
6#[derive(Error, Debug)]
8#[non_exhaustive]
9pub enum Error {
10 #[error(transparent)]
12 IO(#[from] std::io::Error),
13
14 #[error(transparent)]
16 Url(#[from] url::ParseError),
17
18 #[error("unexpected uri format")]
21 UnexpectedURIFormat,
22
23 #[error("mandatory host header missing")]
26 HostHeaderMissing,
27
28 #[error("request path missing")]
30 RequestPathMissing,
31
32 #[error(transparent)]
34 Httparse(#[from] httparse::Error),
35
36 #[error("error type from http_types::Error")]
39 HttpTypes(http_types::Error),
40
41 #[error("partial http head")]
43 PartialHead,
44
45 #[error("malformed http header {0}")]
47 MalformedHeader(&'static str),
48
49 #[error("unsupported http version 1.{0}")]
52 UnsupportedVersion(u8),
53
54 #[error("unsupported http method {0}")]
56 UnrecognizedMethod(String),
57
58 #[error("missing method")]
60 MissingMethod,
61
62 #[error("missing status code")]
64 MissingStatusCode,
65
66 #[error("unrecognized http status code {0}")]
68 UnrecognizedStatusCode(u16),
69
70 #[error("missing version")]
73 MissingVersion,
74
75 #[error(transparent)]
77 EncodingError(#[from] Utf8Error),
78
79 #[error("unexpected header: {0}")]
81 UnexpectedHeader(&'static str),
82
83 #[error("Head byte length should be less than 8kb")]
85 HeadersTooLong,
86}
87impl From<http_types::Error> for Error {
88 fn from(val: http_types::Error) -> Self {
89 Self::HttpTypes(val)
90 }
91}
92
93pub type Result<T> = std::result::Result<T, Error>;