Skip to main content

should_execute

Function should_execute 

Source
pub fn should_execute(conditions: &[Condition], req: &Request) -> bool
Expand description

Returns true if the filter should execute given its conditions.

use praxis_core::config::{Condition, ConditionMatch};
use praxis_filter::{Request, should_execute};

fn make_req(path: &str) -> Request {
    Request {
        headers: http::HeaderMap::new(),
        method: http::Method::GET,
        uri: path.parse().unwrap(),
    }
}

// Empty conditions — always executes.
let req = make_req("/api/v1");
assert!(should_execute(&[], &req));

// When condition matches.
let when = Condition::When(ConditionMatch {
    path: None,
    path_prefix: Some("/api".into()),
    methods: None,
    headers: None,
});
assert!(should_execute(&[when], &req));

// Unless condition matches — skipped.
let unless = Condition::Unless(ConditionMatch {
    path: None,
    path_prefix: Some("/api".into()),
    methods: None,
    headers: None,
});
assert!(!should_execute(&[unless], &req));