1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use crate::http::header::ALLOW;
use crate::response::Response;

use super::AllowedMethods;

/// The default fallback handler for incoming requests that don't match
/// any of the routes you registered.
///
/// It returns a `404 Not Found` response if the path doesn't match any of the
/// registered route paths.  
/// It returns a `405 Method Not Allowed` response if the path matches a
/// registered route path but the method doesn't match any of its associated
/// handlers.
///
/// It also returns a `404 Not Found` response if the path allows all HTTP methods,
/// including custom ones.
pub async fn default_fallback(allowed_methods: &AllowedMethods) -> Response {
    if let Some(header_value) = allowed_methods.allow_header_value() {
        Response::method_not_allowed().insert_header(ALLOW, header_value)
    } else {
        Response::not_found()
    }
}