use vespera_core::route::HttpMethod;
pub fn is_http_method(s: &str) -> bool {
HttpMethod::ALL
.iter()
.any(|method| s.eq_ignore_ascii_case(method.as_str()))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_http_method_valid() {
for method in HttpMethod::ALL {
let upper = method.as_str();
assert!(is_http_method(upper));
assert!(is_http_method(&upper.to_lowercase()));
}
}
#[test]
fn test_is_http_method_invalid() {
assert!(!is_http_method("invalid"));
assert!(!is_http_method("connect"));
assert!(!is_http_method(""));
}
#[test]
fn test_http_methods_includes_trace() {
assert!(HttpMethod::ALL.contains(&HttpMethod::Trace));
}
#[test]
fn test_all_methods_parseable() {
for method in HttpMethod::ALL {
let name = method.as_str();
assert!(is_http_method(name), "Method {name} should be recognized");
}
}
}