@@ -25,9 +25,14 @@ impl<Data> Router<Data> {
25
25
path : & ' a str ,
26
26
method : & http:: Method ,
27
27
) -> Option < ( & ' a BoxedEndpoint < Data > , RouteMatch < ' a > ) > {
28
- self . table
29
- . route ( path)
30
- . and_then ( |( r, p) | Some ( ( r. endpoints . get ( method) ?, p) ) )
28
+ let ( route, route_match) = self . table . route ( path) ?;
29
+ // If it is a HTTP HEAD request then check if there is a callback in the endpoints map
30
+ // if not then fallback to the behavior of HTTP GET else proceed as usual
31
+ if method == http:: Method :: HEAD && !route. endpoints . contains_key ( & http:: Method :: HEAD ) {
32
+ Some ( ( route. endpoints . get ( & http:: Method :: GET ) ?, route_match) )
33
+ } else {
34
+ Some ( ( route. endpoints . get ( method) ?, route_match) )
35
+ }
31
36
}
32
37
}
33
38
@@ -62,6 +67,11 @@ impl<Data> Resource<Data> {
62
67
self . method ( http:: Method :: GET , ep)
63
68
}
64
69
70
+ /// Add an endpoint for `HEAD` requests
71
+ pub fn head < T : Endpoint < Data , U > , U > ( & mut self , ep : T ) {
72
+ self . method ( http:: Method :: HEAD , ep)
73
+ }
74
+
65
75
/// Add an endpoint for `PUT` requests
66
76
pub fn put < T : Endpoint < Data , U > , U > ( & mut self , ep : T ) {
67
77
self . method ( http:: Method :: PUT , ep)
0 commit comments