Fallback to HTTP GET implementation if HEAD implementaion is not present
@@ -25,11 +25,20 @@ impl<Data> Router<Data> {
path: &'a str,
method: &http::Method,
) -> Option<(&'a BoxedEndpoint<Data>, RouteMatch<'a>)> {
+ // If it is a HTTP HEAD request then check if there is a callback in the endpoints map
+ // if not then fallback to the behavior of HTTP GET else proceed as usual
+ if method == http::Method::HEAD &&
+ !self.table.route(path).unwrap().0.endpoints.contains_key(&http::Method::HEAD){
+ self.table
+ .route(path)
+ .and_then(|(r, p)| Some((r.endpoints.get(&http::Method::GET)?, p)))
+ } else {
self.table
.route(path)
.and_then(|(r, p)| Some((r.endpoints.get(method)?, p)))
}
}
+}
/// A resource (identified by a URL).
///
