hyperlane-plugin-idempotency 22.14.1

A production HTTP Idempotency-Key middleware plugin for the Hyperlane framework featuring XxHash3_64 request fingerprinting (422 mismatch), 64-way sharded bounded InMemoryIdempotencyStore + async IdempotencyStore trait, InFlight concurrent duplicate guard (409 Conflict), and zero-copy cached response replay with Idempotent-Replayed headers.
Documentation
/// Default incoming request header carrying the client idempotency key.
pub const DEFAULT_IDEMPOTENCY_KEY_HEADER: &str = "idempotency-key";

/// Response header attached to every replayed idempotent response.
pub const HEADER_IDEMPOTENT_REPLAYED: &str = "idempotent-replayed";

/// Header value emitted on [`HEADER_IDEMPOTENT_REPLAYED`].
pub const HEADER_VALUE_REPLAYED_TRUE: &str = "true";

/// Context attribute key holding the active RAII in-flight guard between request and response hooks.
pub const ATTR_IDEMPOTENCY_GUARD: &str = "hyperlane_plugin_idempotency_guard";

/// Default cached response TTL in milliseconds (24 hours).
pub const DEFAULT_IDEMPOTENCY_TTL_MS: u64 = 86_400_000;

/// Default in-flight lock TTL in milliseconds (60 seconds).
pub const DEFAULT_IN_FLIGHT_TTL_MS: u64 = 60_000;

/// Default maximum distinct idempotency keys stored across all 64 shards.
pub const DEFAULT_IDEMPOTENCY_MAX_ENTRIES: usize = 65_536;

/// Default maximum total memory budget across all 64 shards (64 MiB).
pub const DEFAULT_IDEMPOTENCY_MAX_BYTES: usize = 64 * 1024 * 1024;

/// Default maximum individual response body length eligible for replay caching (4 MiB).
pub const DEFAULT_IDEMPOTENCY_MAX_BODY_BYTES: usize = 4 * 1024 * 1024;

/// Default maximum `Idempotency-Key` header byte length.
pub const DEFAULT_MAX_KEY_LEN: usize = 256;

/// Number of lock-striped shards in [`InMemoryIdempotencyStore`] (power of two).
pub(crate) const IDEMPOTENCY_SHARD_COUNT: usize = 64;

/// Default `Content-Type` header emitted on idempotency error responses (`400`/`409`/`422`).
pub(crate) const ERROR_CONTENT_TYPE: &str = "text/plain; charset=utf-8";

/// Prebuilt response body for `400 Bad Request` invalid or missing `Idempotency-Key`.
pub(crate) const BODY_BAD_KEY: &[u8] = b"Invalid or missing Idempotency-Key";

/// Prebuilt response body for `409 Conflict` when an identical key is currently executing.
pub(crate) const BODY_IN_FLIGHT: &[u8] = b"Request with this Idempotency-Key is in progress";

/// Prebuilt response body for `422 Unprocessable Entity` when key payload fingerprint mismatches.
pub(crate) const BODY_FINGERPRINT_MISMATCH: &[u8] =
    b"Idempotency-Key reused with a different request payload";

/// `Retry-After` seconds value emitted on `409 Conflict` in-flight responses.
pub(crate) const IN_FLIGHT_RETRY_AFTER: &str = "1";

/// HTTP status code threshold above which responses are not cached for replay by default (`500`).
pub(crate) const NON_CACHEABLE_STATUS_MIN: usize = 500;

/// Domain separator byte mixed between method, path, and body during fingerprint hashing.
pub(crate) const FINGERPRINT_SEPARATOR: &[u8] = &[0xFF];

/// Overhead constant in bytes charged per stored entry for memory accounting.
pub(crate) const ENTRY_OVERHEAD_BYTES: usize = 96;