Route request according to {method, path} tuple

Route request according to {method, path} tuple, so we could use only
one router for each http server.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
This commit is contained in:
Liu Jiang
2020-03-23 21:27:24 +08:00
committed by Adrian Catangiu
parent 8ca0839b58
commit 0d87a94c8e
3 changed files with 81 additions and 19 deletions

View File

@@ -177,6 +177,15 @@ impl Method {
Method::Patch => b"PATCH",
}
}
/// Returns an &str corresponding to the Method.
pub fn to_str(self) -> &'static str {
match self {
Method::Get => "GET",
Method::Put => "PUT",
Method::Patch => "PATCH",
}
}
}
/// Supported HTTP Versions.
@@ -367,4 +376,16 @@ mod tests {
"IO error: Resource temporarily unavailable (os error 11)"
);
}
#[test]
fn test_method_to_str() {
let val = Method::Get;
assert_eq!(val.to_str(), "GET");
let val = Method::Put;
assert_eq!(val.to_str(), "PUT");
let val = Method::Patch;
assert_eq!(val.to_str(), "PATCH");
}
}