http_type/http_version/
impl.rs1use crate::*;
2use std::{
3 fmt::{self, Display},
4 str::FromStr,
5};
6
7impl Default for HttpVersion {
8 #[inline]
9 fn default() -> Self {
10 Self::HTTP1_1
11 }
12}
13
14impl Display for HttpVersion {
15 #[inline]
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 let version_str = match self {
18 Self::HTTP1_1 => HTTP_VERSION_1_1,
19 Self::HTTP2 => HTTP_VERSION_2,
20 Self::Unknown(_) => UNKNOWN_HTTP_VERSION,
21 };
22 write!(f, "{}", version_str)
23 }
24}
25
26impl FromStr for HttpVersion {
27 type Err = String;
28
29 #[inline]
30 fn from_str(s: &str) -> Result<Self, Self::Err> {
31 match s {
32 version_1_1 if version_1_1 == HTTP_VERSION_1_1 => Ok(Self::HTTP1_1),
33 version_2 if version_2 == HTTP_VERSION_2 => Ok(Self::HTTP2),
34 _ => Ok(Self::Unknown(s.to_string())),
35 }
36 }
37}