1use serde::{Deserialize, Serialize};
3
4#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
5pub enum HttpMethod {
6 UNKNOWN(String),
7 GET,
8 POST,
9 PUT,
10 PATCH,
11 OPTIONS,
12 CONNECT,
13 HEAD,
14 UNDEFINED,
15}
16
17#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
18pub enum WebProtocol {
19 UNKNOWN(String),
20 HTTP,
21 HTTPS,
22 FTP,
23 WS,
24 WSS,
25}
26impl std::fmt::Display for WebProtocol {
27 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
28 write!(f, "{:?}", self)
29 }
32}
33impl HttpMethod {
34 pub fn from_str_slice(val: &str) -> HttpMethod {
35 match &val.to_uppercase()[..] {
36 "GET" => HttpMethod::GET,
37 "POST" => HttpMethod::POST,
38 "PATCH" => HttpMethod::PATCH,
39 "OPTIONS" => HttpMethod::OPTIONS,
40 "CONNECT" => HttpMethod::CONNECT,
41 "HEAD" => HttpMethod::HEAD,
42 "UNDEFINED" => HttpMethod::UNDEFINED,
43 val => HttpMethod::UNKNOWN(val.to_string()),
44 }
45 }
46
47 pub fn equals(&self, val: &str) -> bool {
48 matches!(
49 (val, self),
50 ("GET", HttpMethod::GET)
51 | ("POST", HttpMethod::POST)
52 | ("PUT", HttpMethod::PUT)
53 | ("PATCH", HttpMethod::PATCH)
54 | ("UNKNOWN", HttpMethod::UNKNOWN(_))
55 | ("OPTIONS", HttpMethod::OPTIONS)
56 | ("CONNECT", HttpMethod::CONNECT)
57 | ("HEAD", HttpMethod::HEAD)
58 | ("UNDEFINED", HttpMethod::UNDEFINED)
59 )
60 }
61}
62impl std::fmt::Display for HttpMethod {
63 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
64 write!(f, "{:?}", self)
65 }
68}