wasmcloud_actor_http_server/
route.rs

1use std::{str::FromStr, string::ParseError};
2/// Valid values for an HTTP method
3#[derive(Clone, Debug, PartialEq, Eq, Hash)]
4pub enum Method {
5    Options,
6    Get,
7    Post,
8    Put,
9    Delete,
10    Head,
11    Trace,
12    Connect,
13    Patch,
14}
15
16impl FromStr for Method {
17    type Err = ParseError;
18
19    fn from_str(input: &str) -> std::result::Result<Self, <Self as FromStr>::Err> {
20        let input = input.to_ascii_uppercase();
21        let input = input.trim();
22
23        Ok(match input {
24            "OPTIONS" => Method::Options,
25            "GET" => Method::Get,
26            "POST" => Method::Post,
27            "PUT" => Method::Put,
28            "DELETE" => Method::Delete,
29            "TRACE" => Method::Trace,
30            "HEAD" => Method::Head,
31            "CONNECT" => Method::Connect,
32            "PATCH" => Method::Patch,
33            _ => Method::Get,
34        })
35    }
36}