pub const HTTP_METHODS: &[&str] = &[
"get", "post", "put", "patch", "delete", "head", "options", "trace",
];
pub fn is_http_method(s: &str) -> bool {
HTTP_METHODS.contains(&s.to_lowercase().as_str())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_http_method_valid() {
for method in HTTP_METHODS {
assert!(is_http_method(method));
assert!(is_http_method(&method.to_uppercase()));
assert!(is_http_method(method));
}
}
#[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!(HTTP_METHODS.contains(&"trace"));
}
#[test]
fn test_all_methods_parseable() {
for method in HTTP_METHODS {
assert!(
is_http_method(method),
"Method {} should be recognized",
method
);
}
}
}