hyperlane-plugin-cors 23.0.0

A zero-allocation precompiled CORS plugin for the Hyperlane framework with exact/suffix/predicate origin matching, safe credential reflection, RFC preflight handling, and Vary header merging.
Documentation
/// Wildcard value used for `Access-Control-Allow-Origin` and header lists.
pub const CORS_WILDCARD: &str = "*";

/// Standard `Access-Control-Allow-Private-Network` response header name.
pub const ACCESS_CONTROL_ALLOW_PRIVATE_NETWORK: &str = "access-control-allow-private-network";

/// Standard `Access-Control-Request-Private-Network` request header name.
pub const ACCESS_CONTROL_REQUEST_PRIVATE_NETWORK: &str = "access-control-request-private-network";

/// Default preflight cache duration in seconds (10 minutes).
pub const DEFAULT_CORS_MAX_AGE_SECS: u64 = 600;

/// Header value emitted for boolean `true` CORS directives.
pub(crate) const HEADER_VALUE_TRUE: &str = "true";

/// Separator used when joining multiple CORS header tokens.
pub(crate) const COMMA_SPACE: &str = ", ";

/// URL scheme separator used when extracting an origin host.
pub(crate) const ORIGIN_SCHEME_SEP: &str = "://";

/// Stack buffer capacity for zero-allocation ASCII lowercasing of incoming origins.
pub(crate) const ORIGIN_LOWER_STACK_CAP: usize = 128;

/// Maximum exact-origin allowlist size scanned linearly without hashing on [`CompiledCors`].
pub(crate) const CORS_SMALL_EXACT_LIMIT: usize = 8;

/// Static HTTP/1.1 preflight `204 No Content` status line and `Access-Control-Allow-Origin: ` prefix.
pub(crate) const PREFLIGHT_WIRE_STATUS_ORIGIN: &[u8] =
    b"HTTP/1.1 204 No Content\r\naccess-control-allow-origin: ";

/// CRLF line terminator used for direct preflight wire assembly.
pub(crate) const PREFLIGHT_WIRE_CRLF: &[u8] = b"\r\n";

/// HTTP/1.1 header name-value separator (`": "`).
pub(crate) const PREFLIGHT_WIRE_COLON_SPACE: &[u8] = b": ";

/// `Access-Control-Allow-Headers: ` prefix for dynamic mirrored preflight headers.
pub(crate) const PREFLIGHT_WIRE_ALLOW_HEADERS: &[u8] = b"access-control-allow-headers: ";

/// `Access-Control-Allow-Private-Network: true\r\n` header line.
pub(crate) const PREFLIGHT_WIRE_PRIVATE_NET: &[u8] =
    b"access-control-allow-private-network: true\r\n";

/// Stack capacity for zero-allocation preflight wire assembly.
pub(crate) const PREFLIGHT_WIRE_STACK_CAP: usize = 512;

/// `Vary` token representing the incoming `Origin` header.
pub(crate) const VARY_ORIGIN: &str = "Origin";

/// `Vary` token for preflight request method negotiation.
pub(crate) const VARY_PREFLIGHT_METHOD: &str = "Access-Control-Request-Method";

/// `Vary` token for preflight request header negotiation.
pub(crate) const VARY_PREFLIGHT_HEADERS: &str = "Access-Control-Request-Headers";

/// Pre-joined `Vary` header value for credentialed or non-wildcard preflight responses.
pub(crate) const VARY_PREFLIGHT_WITH_ORIGIN: &str =
    "Origin, Access-Control-Request-Method, Access-Control-Request-Headers";

/// Pre-joined `Vary` header value for wildcard preflight responses.
pub(crate) const VARY_PREFLIGHT_WITHOUT_ORIGIN: &str =
    "Access-Control-Request-Method, Access-Control-Request-Headers";

/// Default allowed HTTP methods when none are explicitly configured.
pub(crate) const DEFAULT_ALLOWED_METHODS: [&str; 6] =
    ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"];

/// Default allowed request headers when none are explicitly configured.
pub(crate) const DEFAULT_ALLOWED_HEADERS: [&str; 3] =
    ["content-type", "authorization", "x-requested-with"];

/// Debug label rendered for `AllowOrigin::Any`.
pub(crate) const DEBUG_ALLOW_ORIGIN_ANY: &str = "Any";

/// Debug label rendered for `AllowOrigin::Exact`.
pub(crate) const DEBUG_ALLOW_ORIGIN_EXACT: &str = "Exact";

/// Debug label rendered for `AllowOrigin::Suffix`.
pub(crate) const DEBUG_ALLOW_ORIGIN_SUFFIX: &str = "Suffix";

/// Debug label rendered for `AllowOrigin::Custom`.
pub(crate) const DEBUG_ALLOW_ORIGIN_CUSTOM: &str = "Custom(<fn>)";