pavex 0.2.10

A framework for building API services and web applications in Rust.
Documentation
use pavex_macros::fallback;

use crate::Response;
use crate::http::header::ALLOW;

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.
#[fallback(pavex = crate)]
pub async fn default_fallback(allowed_methods: &AllowedMethods) -> Response {
    match allowed_methods.allow_header_value() {
        Some(header_value) => Response::method_not_allowed().insert_header(ALLOW, header_value),
        _ => Response::not_found(),
    }
}