hyperlane-plugin-compression 23.3.0

A full-duplex opt-in compression middleware plugin for the Hyperlane framework providing bounded request decompression (gzip/deflate/br) and automatic Accept-Encoding response negotiation with MIME filtering and Vary merging.
Documentation
/// Default minimum response body size eligible for compression (`1024` bytes).
pub const DEFAULT_MIN_COMPRESS_BYTES: usize = 1024;

/// Default maximum decompressed inbound request payload size (`16 MiB`).
pub const DEFAULT_MAX_DECOMPRESSED_BYTES: usize = 16 * 1024 * 1024;

/// Default decompression buffer chunk size (`8 KiB`).
pub const DEFAULT_DECODE_BUFFER_SIZE: usize = 8192;

/// Default `Content-Type` for compression rejection wire responses.
pub const DEFAULT_ERROR_CONTENT_TYPE: &str = "application/json; charset=utf-8";

/// Default JSON body emitted when an inbound request uses an unsupported `Content-Encoding`.
pub const DEFAULT_UNSUPPORTED_ENCODING_BODY: &[u8] =
    br#"{"error":"unsupported_media_type","message":"unsupported content-encoding"}"#;

/// Default JSON body emitted when a decompressed request exceeds the configured limit.
pub const DEFAULT_DECOMPRESS_LIMIT_BODY: &[u8] =
    br#"{"error":"payload_too_large","message":"decompressed request body exceeds limit"}"#;

/// MIME prefixes skipped by default because payloads are already compressed or streamed.
pub(crate) const DEFAULT_SKIP_MIME_PREFIXES: &[&str] = &[
    "image/",
    "video/",
    "audio/",
    "font/",
    "application/zip",
    "application/gzip",
    "application/x-gzip",
    "application/zstd",
    "application/octet-stream",
    "text/event-stream",
];

/// Cache-Control directive disallowing intermediaries from applying content codings.
pub(crate) const CACHE_CONTROL_NO_TRANSFORM: &str = "no-transform";

/// Identity content-encoding token.
pub(crate) const CONTENT_ENCODING_IDENTITY: &str = "identity";

/// Lowercase ASCII `gzip` token bytes for zero-allocation fallback negotiation.
pub(crate) const GZIP_TOKEN_BYTES: &[u8] = b"gzip";

/// Lowercase ASCII `deflate` token bytes for zero-allocation fallback negotiation.
pub(crate) const DEFLATE_TOKEN_BYTES: &[u8] = b"deflate";

/// Wildcard `Vary` header value.
pub(crate) const VARY_WILDCARD: &str = "*";