File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,18 @@ impl<State: 'static> Router<State> {
61
61
// if not then fallback to the behavior of HTTP GET else proceed as usual
62
62
63
63
self . route ( path, http:: Method :: GET )
64
+ } else if self
65
+ . method_map
66
+ . iter ( )
67
+ . filter ( |( k, _) | * k != method)
68
+ . any ( |( _, r) | r. recognize ( path) . is_ok ( ) )
69
+ {
70
+ // If this `path` can be handled by a callback registered with a different HTTP method
71
+ // should return 405 Method Not Allowed
72
+ Selection {
73
+ endpoint : & method_not_allowed,
74
+ params : Params :: new ( ) ,
75
+ }
64
76
} else {
65
77
Selection {
66
78
endpoint : & not_found_endpoint,
@@ -73,3 +85,7 @@ impl<State: 'static> Router<State> {
73
85
fn not_found_endpoint < State > ( _cx : Request < State > ) -> BoxFuture < ' static , Response > {
74
86
Box :: pin ( async move { Response :: new ( http:: StatusCode :: NOT_FOUND . as_u16 ( ) ) } )
75
87
}
88
+
89
+ fn method_not_allowed < State > ( _cx : Request < State > ) -> BoxFuture < ' static , Response > {
90
+ Box :: pin ( async move { Response :: new ( http:: StatusCode :: METHOD_NOT_ALLOWED . as_u16 ( ) ) } )
91
+ }
You can’t perform that action at this time.
0 commit comments