webserver_colin_ugo/http/
method.rs1#[derive(Debug, Clone, Copy, PartialEq)]
3pub enum HttpMethod {
4 GET,
5 HEAD,
6}
7
8impl HttpMethod {
9 pub fn from_str(method: &str) -> Option<HttpMethod> {
19 match method {
20 "GET" => Some(HttpMethod::GET),
21 "HEAD" => Some(HttpMethod::HEAD),
22 _ => None,
23 }
24 }
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30
31 #[test]
32 fn test_http_method_from_str() {
33 match HttpMethod::from_str("GET") {
35 Some(HttpMethod::GET) => assert!(true),
36 _ => panic!("La méthode GET n'a pas été correctement analysée"),
37 }
38
39 assert!(HttpMethod::from_str("POST").is_none());
41 assert!(HttpMethod::from_str("PUT").is_none());
42 assert!(HttpMethod::from_str("DELETE").is_none());
43
44 assert!(HttpMethod::from_str("INVALID").is_none());
46 }
47}