diff options
| author | Andrew <saintruler@gmail.com> | 2021-02-14 18:14:16 +0400 |
|---|---|---|
| committer | Andrew <saintruler@gmail.com> | 2021-02-14 18:14:16 +0400 |
| commit | e59827e90c65f781cf054b52614308f538f7b018 (patch) | |
| tree | fee613c809995d358cba47198917c875c9913a23 /spider/src/http_method.rs | |
| parent | 5ed195f981ccda099926c1fe2a8603d110eb417c (diff) | |
Added rest of HTTP methods and default handler for unhandled methods.
Diffstat (limited to 'spider/src/http_method.rs')
| -rw-r--r-- | spider/src/http_method.rs | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/spider/src/http_method.rs b/spider/src/http_method.rs index e308983..a0b2e17 100644 --- a/spider/src/http_method.rs +++ b/spider/src/http_method.rs @@ -1,29 +1,38 @@ use std::fmt; -// TODO(andrew): add rest of the methods. pub enum HttpMethod { - GET, POST + GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE, PATCH } impl fmt::Display for HttpMethod { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - HttpMethod::GET => write!(f, "GET"), - HttpMethod::POST => write!(f, "POST") + HttpMethod::GET => write!(f, "GET"), + HttpMethod::HEAD => write!(f, "HEAD"), + HttpMethod::POST => write!(f, "POST"), + HttpMethod::PUT => write!(f, "PUT"), + HttpMethod::DELETE => write!(f, "DELETE"), + HttpMethod::CONNECT => write!(f, "CONNECT"), + HttpMethod::OPTIONS => write!(f, "OPTIONS"), + HttpMethod::TRACE => write!(f, "TRACE"), + HttpMethod::PATCH => write!(f, "PATCH"), } } } impl HttpMethod { pub fn parse(s: String) -> Option<HttpMethod> { - if s == "GET" { - return Some(HttpMethod::GET); - } - else if s == "POST" { - return Some(HttpMethod::POST); - } - else { - return None; + match &*s { + "GET" => Some(HttpMethod::GET), + "HEAD" => Some(HttpMethod::HEAD), + "POST" => Some(HttpMethod::POST), + "PUT" => Some(HttpMethod::PUT), + "DELETE" => Some(HttpMethod::DELETE), + "CONNECT" => Some(HttpMethod::CONNECT), + "OPTIONS" => Some(HttpMethod::OPTIONS), + "TRACE" => Some(HttpMethod::TRACE), + "PATCH" => Some(HttpMethod::PATCH), + _ => None } } } |