use crate::{
field::{
Error,
metadata::{block::Validation, map::record::Span},
},
payload::response,
};
#[derive(Clone, Copy, PartialEq, Eq)]
pub(super) enum Method {
Other,
Options,
Connect,
Head,
}
impl Method {
pub(super) fn parse(value: Span<'_>, push: bool) -> Result<Self, Validation> {
match value.len() {
0 => Err(Validation::Malformed),
3 if value.is_equal(b"GET") => Ok(Self::Other),
4 if value.is_equal(b"HEAD") => Ok(Self::Head),
7 if !push && value.is_equal(b"CONNECT") => Ok(Self::Connect),
7 if !push && value.is_equal(b"OPTIONS") => Ok(Self::Options),
_ if !value.iter().copied().all(Error::is_name_byte) => Err(Validation::Malformed),
_ if push => Err(Validation::RejectPush),
_ => Ok(Self::Other),
}
}
pub(super) const fn response(self) -> response::Method {
match self {
Self::Other | Self::Options => response::Method::Other,
Self::Connect => response::Method::Connect,
Self::Head => response::Method::Head,
}
}
}