hyperlane-plugin-etag 23.3.2

An opt-in automatic ETag and HTTP conditional request plugin for the Hyperlane framework providing strong/weak XxHash3_64 entity tags, zero-allocation If-None-Match 304 Not Modified, and If-Match 412 Precondition Failed optimistic concurrency.
Documentation
use super::*;

/// Configuration for [`EtagPlugin`].
#[derive(Clone, Data, Debug, Eq, PartialEq)]
pub struct EtagConfig {
    /// Generated tag strength (`Strong` or `Weak`).
    #[get(type(copy))]
    pub(crate) strength: EtagStrength,
    /// Minimum response body length eligible for automatic ETag computation.
    #[get(type(copy))]
    pub(crate) min_body_bytes: usize,
    /// Path prefixes excluded from automatic ETag generation and conditional checks.
    pub(crate) exempt_prefixes: Vec<String>,
    /// Whether to enforce `If-Match` preconditions on mutating methods when an [`EtagValidator`] is registered.
    #[get(type(copy))]
    pub(crate) enforce_if_match: bool,
}

/// Precompiled ETag engine backing [`EtagRequestHook`] and [`EtagResponseHook`].
pub struct EtagPlugin {
    /// Retained configuration.
    pub(crate) config: EtagConfig,
    /// Normalized exempt prefixes.
    pub(crate) exempt_prefixes: Box<[String]>,
    /// Optional optimistic-locking validator for `If-Match` requests.
    pub(crate) validator: Option<Arc<dyn EtagValidator>>,
    /// Prebuilt `412 Precondition Failed` wire response.
    pub(crate) precondition_failed_wire: Vec<u8>,
}

/// Opt-in request middleware enforcing `If-Match` preconditions (`412 Precondition Failed`).
#[derive(Clone, Copy, Debug, Default)]
#[hyperlane::request_middleware(-72)]
pub struct EtagRequestHook;

/// Opt-in response middleware generating `ETag` headers and converting matching `If-None-Match` to `304`.
#[derive(Clone, Copy, Debug, Default)]
#[hyperlane::response_middleware(-58)]
pub struct EtagResponseHook;