http_type/upgrade_type/
impl.rs1use crate::*;
2
3impl Default for UpgradeType {
4 fn default() -> Self {
5 Self::Unknown(String::new())
6 }
7}
8
9impl fmt::Display for UpgradeType {
10 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
11 match self {
12 Self::WebSocket => write!(f, "{}", WEBSOCKET),
13 Self::H2c => write!(f, "{}", H2C_LOWERCASE),
14 Self::Tls(version) => write!(f, "{}", version),
15 Self::Unknown(tmp_str) => write!(f, "{}", tmp_str),
16 }
17 }
18}
19
20impl FromStr for UpgradeType {
21 type Err = ();
22
23 fn from_str(from_str: &str) -> Result<Self, Self::Err> {
24 match from_str.to_ascii_lowercase().as_str() {
25 val if val == WEBSOCKET => Ok(Self::WebSocket),
26 H2C_LOWERCASE => Ok(Self::H2c),
27 val if val.starts_with(TLS_LOWERCASE) => Ok(Self::Tls(val.to_string())),
28 other => Ok(Self::Unknown(other.to_string())),
29 }
30 }
31}
32
33impl UpgradeType {
34 pub fn is_ws(&self) -> bool {
40 matches!(self, &Self::WebSocket)
41 }
42
43 pub fn is_h2c(&self) -> bool {
49 matches!(self, &Self::H2c)
50 }
51
52 pub fn is_tls(&self) -> bool {
58 matches!(self, Self::Tls(_))
59 }
60
61 pub fn is_unknown(&self) -> bool {
67 !self.is_ws() && !self.is_h2c() && !self.is_tls()
68 }
69}