hyperlane-plugin-idempotency 23.3.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;

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

/// First SplitMix64 multiplier used for 8-byte word shard hashing.
pub(crate) const IDEMP_SHARD_MUL1: u64 = 0xBF58_476D_1CE4_E5B9;

/// Second SplitMix64 multiplier used for tail word shard hashing.
pub(crate) const IDEMP_SHARD_MUL2: u64 = 0x94D0_49BB_1331_11EB;

/// Stack buffer capacity for formatting `usize` status codes and `Content-Length` values.
pub(crate) const DEC_STACK_BUF_LEN: usize = 20;

/// Stack buffer capacity for zero-allocation scoped storage key assembly during lookup.
pub(crate) const STACK_STORAGE_KEY_CAP: usize = 256;

/// Prebuilt HTTP/1.1 status line prefix.
pub(crate) const WIRE_HTTP11_PREFIX: &[u8] = b"HTTP/1.1 ";

/// HTTP/1.1 header line terminator.
pub(crate) const WIRE_CRLF: &[u8] = b"\r\n";

/// Prebuilt `Idempotent-Replayed: true` HTTP wire header line.
pub(crate) const WIRE_REPLAYED_LINE: &[u8] = b"idempotent-replayed:true\r\n";

/// Prebuilt default `Connection: keep-alive` HTTP wire header line.
pub(crate) const WIRE_CONN_KEEP_ALIVE: &[u8] = b"connection:keep-alive\r\n";

/// Prebuilt default `Content-Type` HTTP wire header line matching `Response::build`.
pub(crate) const WIRE_DEFAULT_CONTENT_TYPE: &[u8] = b"content-type:text/html; charset=utf-8\r\n";

/// Prebuilt `Content-Length:` HTTP wire header prefix.
pub(crate) const WIRE_CL_PREFIX: &[u8] = b"content-length:";

/// Prebuilt `Content-Length: 0` wire header line for `205 Reset Content`.
pub(crate) const WIRE_CL_ZERO: &[u8] = b"content-length:0\r\n";

/// First wyhash secret constant used for zero-allocation 64-bit request fingerprinting.
pub(crate) const FP_SECRET0: u64 = 0xa076_1d64_78bd_642f;

/// ASCII vertical-bar delimiter byte (`|`).
pub(crate) const ASCII_PIPE: u8 = b'|';

/// ASCII digit zero byte (`0`).
pub(crate) const ASCII_ZERO: u8 = b'0';

/// ASCII colon byte (`:`).
pub(crate) const ASCII_COLON: u8 = b':';

/// Second wyhash secret constant used for zero-allocation 64-bit request fingerprinting.
pub(crate) const FP_SECRET1: u64 = 0xe703_7ed1_a0b4_28db;

/// Third wyhash secret constant used for zero-allocation 64-bit request fingerprinting.
pub(crate) const FP_SECRET2: u64 = 0x8ebc_6af0_9c88_c6e3;

/// Fourth wyhash secret constant used for zero-allocation 64-bit request fingerprinting.
pub(crate) const FP_SECRET3: u64 = 0x5899_65cc_7537_4cc3;