async_h1b/
error.rs

1use std::str::Utf8Error;
2
3use http_types::url;
4use thiserror::Error;
5
6/// Concrete errors that occur within async-h1
7#[derive(Error, Debug)]
8#[non_exhaustive]
9pub enum Error {
10    /// [`std::io::Error`]
11    #[error(transparent)]
12    IO(#[from] std::io::Error),
13
14    /// [`url::ParseError`]
15    #[error(transparent)]
16    Url(#[from] url::ParseError),
17
18    /// this error describes a malformed request with a path that does
19    /// not start with / or http:// or https://
20    #[error("unexpected uri format")]
21    UnexpectedURIFormat,
22
23    /// this error describes a http 1.1 request that is missing a Host
24    /// header
25    #[error("mandatory host header missing")]
26    HostHeaderMissing,
27
28    /// this error describes a request that does not specify a path
29    #[error("request path missing")]
30    RequestPathMissing,
31
32    /// [`httparse::Error`]
33    #[error(transparent)]
34    Httparse(#[from] httparse::Error),
35
36    /// [`http_types::Error`]
37    //#[error(transparent)]
38    #[error("error type from http_types::Error")]
39    HttpTypes(/*#[from] */http_types::Error),
40
41    /// an incomplete http head
42    #[error("partial http head")]
43    PartialHead,
44
45    /// we were unable to parse a header
46    #[error("malformed http header {0}")]
47    MalformedHeader(&'static str),
48
49    /// async-h1 doesn't speak this http version
50    /// this error is deprecated
51    #[error("unsupported http version 1.{0}")]
52    UnsupportedVersion(u8),
53
54    /// we were unable to parse this http method
55    #[error("unsupported http method {0}")]
56    UnrecognizedMethod(String),
57
58    /// this request did not have a method
59    #[error("missing method")]
60    MissingMethod,
61
62    /// this request did not have a status code
63    #[error("missing status code")]
64    MissingStatusCode,
65
66    /// we were unable to parse this http method
67    #[error("unrecognized http status code {0}")]
68    UnrecognizedStatusCode(u16),
69
70    /// this request did not have a version, but we expect one
71    /// this error is deprecated
72    #[error("missing version")]
73    MissingVersion,
74
75    /// we expected utf8, but there was an encoding error
76    #[error(transparent)]
77    EncodingError(#[from] Utf8Error),
78
79    /// we received a header that does not make sense in context
80    #[error("unexpected header: {0}")]
81    UnexpectedHeader(&'static str),
82
83    /// for security reasons, we do not allow request headers beyond 8kb.
84    #[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
93/// this crate's result type
94pub type Result<T> = std::result::Result<T, Error>;