hyperlane-plugin-rewrite 22.14.0

A high-performance HTTP URL rewrite and redirect plugin for the Hyperlane framework featuring canonical host/HTTPS enforcement (X-Forwarded-Proto aware), trailing-slash and duplicate-slash normalization, O(1) XxHash3_64 static tables, segment-bounded prefix rules, and compiled regex rules.
Documentation
/// Supported HTTP redirect status codes for short-circuit rewrite rules.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum RedirectStatus {
    /// `301 Moved Permanently`
    MovedPermanently301,
    /// `302 Found`
    Found302,
    /// `307 Temporary Redirect` (preserves HTTP method and body).
    Temporary307,
    /// `308 Permanent Redirect` (preserves HTTP method and body).
    #[default]
    Permanent308,
}

/// Action taken when a rewrite rule matches an incoming request path.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum RewriteAction {
    /// Mutates `Request::set_path` internally and continues routing.
    #[default]
    InternalRewrite,
    /// Short-circuits the pipeline with an HTTP redirect and `Location` header.
    Redirect(RedirectStatus),
}

/// Trailing-slash normalization policy applied to non-root paths (`path != "/"`).
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum TrailingSlashMode {
    /// Leave trailing slashes untouched.
    #[default]
    Keep,
    /// Remove trailing slashes (`/docs/` -> `/docs`).
    Strip,
    /// Ensure a trailing slash (`/docs` -> `/docs/`).
    Enforce,
}

/// Outcome returned by [`CompiledRewrite::apply`] when evaluating a request context.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum RewriteOutcome {
    /// No canonical redirect or rewrite rule matched (zero-allocation fast path).
    Unchanged,
    /// Request path was internally rewritten via `Request::set_path`.
    Rewritten(String),
    /// Response was populated with a redirect status and `Location` header ready to send.
    Redirected {
        /// HTTP redirect status code (`301`/`302`/`307`/`308`).
        status_code: usize,
        /// Target `Location` header value.
        location: String,
    },
}

/// Errors produced when compiling [`RewriteConfig`] into [`CompiledRewrite`].
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum RewriteError {
    /// A configured regex pattern failed to compile.
    InvalidRegex {
        /// Source pattern string.
        pattern: String,
        /// Underlying regex parser diagnostic.
        message: String,
    },
    /// A configured canonical host or target contained forbidden CR/LF control characters.
    UnsafeLocation(String),
}