Skip to content

Commit

Permalink
Fallback to HTTP GET implementation if HEAD implementaion is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaManiac committed Nov 9, 2018
1 parent 013be3c commit aeba74d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@ impl<Data> Router<Data> {
path: &'a str,
method: &http::Method,
) -> Option<(&'a BoxedEndpoint<Data>, RouteMatch<'a>)> {
self.table
.route(path)
.and_then(|(r, p)| Some((r.endpoints.get(method)?, p)))
// 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)))
}
}
}

Expand Down

0 comments on commit aeba74d

Please sign in to comment.