hyperlane_plugin_etag/struct.rs
1use super::*;
2
3/// Configuration for [`EtagPlugin`].
4#[derive(Clone, Data, Debug, Eq, PartialEq)]
5pub struct EtagConfig {
6 /// Generated tag strength (`Strong` or `Weak`).
7 #[get(type(copy))]
8 pub(crate) strength: EtagStrength,
9 /// Minimum response body length eligible for automatic ETag computation.
10 #[get(type(copy))]
11 pub(crate) min_body_bytes: usize,
12 /// Path prefixes excluded from automatic ETag generation and conditional checks.
13 pub(crate) exempt_prefixes: Vec<String>,
14 /// Whether to enforce `If-Match` preconditions on mutating methods when an [`EtagValidator`] is registered.
15 #[get(type(copy))]
16 pub(crate) enforce_if_match: bool,
17}
18
19/// Precompiled ETag engine backing [`EtagRequestHook`] and [`EtagResponseHook`].
20pub struct EtagPlugin {
21 /// Retained configuration.
22 pub(crate) config: EtagConfig,
23 /// Normalized exempt prefixes.
24 pub(crate) exempt_prefixes: Box<[String]>,
25 /// Optional optimistic-locking validator for `If-Match` requests.
26 pub(crate) validator: Option<Arc<dyn EtagValidator>>,
27 /// Prebuilt `412 Precondition Failed` wire response.
28 pub(crate) precondition_failed_wire: Vec<u8>,
29}
30
31/// Opt-in request middleware enforcing `If-Match` preconditions (`412 Precondition Failed`).
32#[derive(Clone, Copy, Debug, Default)]
33#[hyperlane::request_middleware(-72)]
34pub struct EtagRequestHook;
35
36/// Opt-in response middleware generating `ETag` headers and converting matching `If-None-Match` to `304`.
37#[derive(Clone, Copy, Debug, Default)]
38#[hyperlane::response_middleware(-58)]
39pub struct EtagResponseHook;