1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::{str::FromStr, string::ParseError};
/// Valid values for an HTTP method
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Method {
    Options,
    Get,
    Post,
    Put,
    Delete,
    Head,
    Trace,
    Connect,
    Patch,
}

impl FromStr for Method {
    type Err = ParseError;

    fn from_str(input: &str) -> std::result::Result<Self, <Self as FromStr>::Err> {
        let input = input.to_ascii_uppercase();
        let input = input.trim();

        Ok(match input {
            "OPTIONS" => Method::Options,
            "GET" => Method::Get,
            "POST" => Method::Post,
            "PUT" => Method::Put,
            "DELETE" => Method::Delete,
            "TRACE" => Method::Trace,
            "HEAD" => Method::Head,
            "CONNECT" => Method::Connect,
            "PATCH" => Method::Patch,
            _ => Method::Get,
        })
    }
}