coraza 0.1.0

Safe Rust bindings to OWASP Coraza WAF
/*
 * Copyright 2022 OWASP Coraza contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/// The result of a rule matching during request processing.
///
/// When a rule fires, Coraza creates an intervention that describes the action
/// to take. Retrieve this via [`Transaction::intervention()`](crate::Transaction::intervention).
#[derive(Debug, Clone)]
pub struct Intervention {
    /// The action taken (e.g., `"deny"`, `"redirect"`, `"drop"`, `"pass"`).
    pub action: String,
    /// The HTTP status code (e.g., `403`, `302`).
    pub status: i32,
    /// Additional data, such as a redirect URL for `"redirect"` actions.
    pub data: Option<String>,
    /// The rule ID that triggered this intervention.
    pub rule_id: i32,
}

impl Intervention {
    /// Returns `true` if this is a disruptive intervention (deny/drop/redirect).
    pub fn is_disruptive(&self) -> bool {
        matches!(self.action.as_str(), "deny" | "drop" | "redirect")
    }

    /// Returns `true` if this is a redirect intervention.
    pub fn is_redirect(&self) -> bool {
        self.action == "redirect"
    }
}