use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HttpVersion {
Http10,
Http11,
Http20,
}
impl HttpVersion {
pub fn as_str(&self) -> &'static str {
match self {
Self::Http10 => "HTTP/1.0",
Self::Http11 => "HTTP/1.1",
Self::Http20 => "HTTP/2.0",
}
}
pub fn from_str(s: &str) -> Option<Self> {
match s.to_ascii_uppercase().as_str() {
"HTTP/1.0" => Some(Self::Http10),
"HTTP/1.1" => Some(Self::Http11),
"HTTP/2.0" | "HTTP/2" => Some(Self::Http20),
_ => None,
}
}
}
impl fmt::Display for HttpVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_str())
}
}