Method checking in static routes; tests for it

Signed-off-by: Erik Hollensbe <linux@hollensbe.org>
This commit is contained in:
Erik Hollensbe
2022-01-19 14:28:44 -08:00
parent 86bd836846
commit 7727fed746
+15
View File
@@ -44,6 +44,11 @@ impl Route {
#[allow(dead_code)]
async fn dispatch(&self, provided: &'static str, req: Request<hyper::Body>) -> HTTPResult {
let params = self.path.extract(provided)?;
if self.method != req.method() {
return Err(Error(http::StatusCode::NOT_FOUND.to_string()));
}
self.handler.perform(req, None, params).await
}
}
@@ -112,6 +117,16 @@ mod tests {
);
assert!(route.dispatch("/a", Request::default()).await.is_err());
assert!(route
.dispatch(
"/a/b/c",
Request::builder()
.method(Method::POST)
.body(Body::from("one=two".as_bytes()))
.unwrap(),
)
.await
.is_err());
assert!(route.dispatch("/a/b/c", Request::default()).await.is_ok());