hyperlane-plugin-negotiate 23.1.0

A response negotiation plugin for the Hyperlane framework, answering with the content coding the client accepts and with 304 Not Modified while a validator still matches.
Documentation
/// The body length below which a response is answered without a content coding.
pub(crate) const DEFAULT_MIN_LENGTH: usize = 256;

/// The prefix marking a weak HTTP entity-tag per RFC 9110.
pub(crate) const WEAK_ETAG_PREFIX: &str = "W/";

/// ASCII double-quote byte framing HTTP entity-tag values.
pub(crate) const BYTE_QUOTE: u8 = b'"';

/// ASCII uppercase `'W'` byte starting a weak entity-tag prefix.
pub(crate) const BYTE_UPPER_W: u8 = b'W';

/// ASCII forward-slash byte completing a weak entity-tag prefix.
pub(crate) const BYTE_SLASH: u8 = b'/';

/// ASCII semicolon byte introducing quality-value parameters in `Accept-Encoding`.
pub(crate) const BYTE_SEMICOLON: u8 = b';';

/// ASCII comma byte joining multiple `Accept-Encoding` header values.
pub(crate) const BYTE_COMMA: u8 = b',';

/// ASCII asterisk wildcard byte in `Accept-Encoding`.
pub(crate) const BYTE_STAR: u8 = b'*';

/// ASCII space byte trimmed as HTTP optional whitespace.
pub(crate) const BYTE_SPACE: u8 = b' ';

/// ASCII horizontal tab byte trimmed as HTTP optional whitespace.
pub(crate) const BYTE_TAB: u8 = b'\t';

/// Highest ASCII control byte disallowed inside RFC 9110 entity-tag opaque-tag bytes.
pub(crate) const BYTE_CTL_LIMIT: u8 = 0x1F;

/// ASCII DEL byte disallowed inside RFC 9110 entity-tag opaque-tag bytes.
pub(crate) const BYTE_DEL: u8 = 0x7F;

/// 256-entry 2-byte lowercase hexadecimal lookup table for branchless ETag formatting.
pub(crate) const HEX_ENCODE_PAIRS: [[u8; 2]; 256] = {
    const DIGITS: &[u8; 16] = b"0123456789abcdef";
    let mut table: [[u8; 2]; 256] = [[0u8; 2]; 256];
    let mut i: usize = 0;
    while i < 256 {
        table[i] = [DIGITS[i >> 4], DIGITS[i & 0x0F]];
        i += 1;
    }
    table
};

/// Maximum input length delegated directly to stack-buffered `XxHash3_64`.
pub(crate) const XXH3_SHORT_LIMIT: usize = 128;

/// Whether ARM64 little-endian NEON acceleration is available at compile time.
pub(crate) const USE_AARCH64_NEON: bool = cfg!(all(
    target_arch = "aarch64",
    target_feature = "neon",
    target_endian = "little"
));

/// Maximum input length handled by the XXH3 medium-key algorithm.
pub(crate) const XXH3_MID_LIMIT: usize = 240;

/// XXH3 32-bit prime 1.
pub(crate) const XXH3_PRIME32_1: u64 = 0x9E37_79B1;

/// XXH3 32-bit prime 2.
pub(crate) const XXH3_PRIME32_2: u64 = 0x85EB_CA77;

/// XXH3 32-bit prime 3.
pub(crate) const XXH3_PRIME32_3: u64 = 0xC2B2_AE3D;

/// XXH3 64-bit prime 1.
pub(crate) const XXH3_PRIME64_1: u64 = 0x9E37_79B1_85EB_CA87;

/// XXH3 64-bit prime 2.
pub(crate) const XXH3_PRIME64_2: u64 = 0xC2B2_AE3D_27D4_EB4F;

/// XXH3 64-bit prime 3.
pub(crate) const XXH3_PRIME64_3: u64 = 0x1656_67B1_9E37_79F9;

/// XXH3 64-bit prime 4.
pub(crate) const XXH3_PRIME64_4: u64 = 0x85EB_CA77_C2B2_AE63;

/// XXH3 64-bit prime 5.
pub(crate) const XXH3_PRIME64_5: u64 = 0x27D4_EB2F_1656_67C5;

/// XXH3 avalanche mixing constant.
pub(crate) const XXH3_PRIME_MX1: u64 = 0x1656_6791_9E37_79F9;

/// Initial 8-lane XXH3 accumulator vector.
pub(crate) const XXH3_INIT_ACC: [u64; 8] = [
    XXH3_PRIME32_3,
    XXH3_PRIME64_1,
    XXH3_PRIME64_2,
    XXH3_PRIME64_3,
    XXH3_PRIME64_4,
    XXH3_PRIME32_2,
    XXH3_PRIME64_5,
    XXH3_PRIME32_1,
];

/// Standard 192-byte default secret specified by XXH3.
pub(crate) const XXH3_DEFAULT_SECRET: [u8; 192] = [
    0xb8, 0xfe, 0x6c, 0x39, 0x23, 0xa4, 0x4b, 0xbe, 0x7c, 0x01, 0x81, 0x2c, 0xf7, 0x21, 0xad, 0x1c,
    0xde, 0xd4, 0x6d, 0xe9, 0x83, 0x90, 0x97, 0xdb, 0x72, 0x40, 0xa4, 0xa4, 0xb7, 0xb3, 0x67, 0x1f,
    0xcb, 0x79, 0xe6, 0x4e, 0xcc, 0xc0, 0xe5, 0x78, 0x82, 0x5a, 0xd0, 0x7d, 0xcc, 0xff, 0x72, 0x21,
    0xb8, 0x08, 0x46, 0x74, 0xf7, 0x43, 0x24, 0x8e, 0xe0, 0x35, 0x90, 0xe6, 0x81, 0x3a, 0x26, 0x4c,
    0x3c, 0x28, 0x52, 0xbb, 0x91, 0xc3, 0x00, 0xcb, 0x88, 0xd0, 0x65, 0x8b, 0x1b, 0x53, 0x2e, 0xa3,
    0x71, 0x64, 0x48, 0x97, 0xa2, 0x0d, 0xf9, 0x4e, 0x38, 0x19, 0xef, 0x46, 0xa9, 0xde, 0xac, 0xd8,
    0xa8, 0xfa, 0x76, 0x3f, 0xe3, 0x9c, 0x34, 0x3f, 0xf9, 0xdc, 0xbb, 0xc7, 0xc7, 0x0b, 0x4f, 0x1d,
    0x8a, 0x51, 0xe0, 0x4b, 0xcd, 0xb4, 0x59, 0x31, 0xc8, 0x9f, 0x7e, 0xc9, 0xd9, 0x78, 0x73, 0x64,
    0xea, 0xc5, 0xac, 0x83, 0x34, 0xd3, 0xeb, 0xc3, 0xc5, 0x81, 0xa0, 0xff, 0xfa, 0x13, 0x63, 0xeb,
    0x17, 0x0d, 0xdd, 0x51, 0xb7, 0xf0, 0xda, 0x49, 0xd3, 0x16, 0x55, 0x26, 0x29, 0xd4, 0x68, 0x9e,
    0x2b, 0x16, 0xbe, 0x58, 0x7d, 0x47, 0xa1, 0xfc, 0x8f, 0xf8, 0xb8, 0xd1, 0x7a, 0xd0, 0x31, 0xce,
    0x45, 0xcb, 0x3a, 0x8f, 0x95, 0x16, 0x04, 0x28, 0xaf, 0xd7, 0xfb, 0xca, 0xbb, 0x4b, 0x40, 0x7e,
];

/// The parameter delimiter inside a `Content-Type` header value.
pub(crate) const MEDIA_TYPE_PARAM_DELIMITER: char = ';';

/// The `Cache-Control` directive forbidding response body transformation.
pub(crate) const CACHE_CONTROL_NO_TRANSFORM: &str = "no-transform";

/// The wildcard token in a `Vary` header field.
pub(crate) const VARY_WILDCARD: &str = "*";

/// Error reported when `CompressMiddleware::init` is called more than once.
pub(crate) const COMPRESS_CONFIG_ALREADY_SET: &str = "the compress configuration was already set";

/// Stack buffer capacity in bytes for joining multiple `Accept-Encoding` header values without heap allocation.
pub(crate) const STACK_ACCEPT_ENCODING_CAP: usize = 256;

/// Response inspection state indicating the response must not be compressed.
pub(crate) const COMPRESS_STATE_SKIP: u8 = 0;

/// Response inspection state indicating `Vary: Accept-Encoding` should be inserted.
pub(crate) const COMPRESS_STATE_SET_VARY: u8 = 1;

/// Response inspection state indicating `Accept-Encoding` should be appended to an existing `Vary` header.
pub(crate) const COMPRESS_STATE_ADD_VARY: u8 = 2;

/// Response inspection state indicating `Vary` already covers `Accept-Encoding` or `*`.
pub(crate) const COMPRESS_STATE_VARY_OK: u8 = 3;

/// Brotli content-coding token for fast-path negotiation.
pub(crate) const CODING_BR: &str = "br";

/// Gzip content-coding token for fast-path negotiation.
pub(crate) const CODING_GZIP: &str = "gzip";

/// Legacy x-gzip content-coding token for fast-path negotiation.
pub(crate) const CODING_X_GZIP: &str = "x-gzip";

/// Deflate content-coding token for fast-path negotiation.
pub(crate) const CODING_DEFLATE: &str = "deflate";