use std::str::Utf8Error;
use http_types::url;
use thiserror::Error;
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[error(transparent)]
IO(#[from] std::io::Error),
#[error(transparent)]
Url(#[from] url::ParseError),
#[error("unexpected uri format")]
UnexpectedURIFormat,
#[error("mandatory host header missing")]
HostHeaderMissing,
#[error("request path missing")]
RequestPathMissing,
#[error(transparent)]
Httparse(#[from] httparse::Error),
#[error("error type from http_types::Error")]
HttpTypes(http_types::Error),
#[error("partial http head")]
PartialHead,
#[error("malformed http header {0}")]
MalformedHeader(&'static str),
#[error("unsupported http version 1.{0}")]
UnsupportedVersion(u8),
#[error("unsupported http method {0}")]
UnrecognizedMethod(String),
#[error("missing method")]
MissingMethod,
#[error("missing status code")]
MissingStatusCode,
#[error("unrecognized http status code {0}")]
UnrecognizedStatusCode(u16),
#[error("missing version")]
MissingVersion,
#[error(transparent)]
EncodingError(#[from] Utf8Error),
#[error("unexpected header: {0}")]
UnexpectedHeader(&'static str),
#[error("Head byte length should be less than 8kb")]
HeadersTooLong,
}
impl From<http_types::Error> for Error {
fn from(val: http_types::Error) -> Self {
Self::HttpTypes(val)
}
}
pub type Result<T> = std::result::Result<T, Error>;