Function actix_web::guard::fn_guard

source ·
pub fn fn_guard<F>(f: F) -> impl Guard
where F: Fn(&GuardContext<'_>) -> bool,
Expand description

Creates a guard using the given function.

§Examples

use actix_web::{guard, web, HttpResponse};

web::route()
    .guard(guard::fn_guard(|ctx| {
        ctx.head().headers().contains_key("content-type")
    }))
    .to(|| HttpResponse::Ok());