Skip to main content

hyperlane_plugin_rewrite/
enum.rs

1/// Supported HTTP redirect status codes for short-circuit rewrite rules.
2#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
3pub enum RedirectStatus {
4    /// `301 Moved Permanently`
5    MovedPermanently301,
6    /// `302 Found`
7    Found302,
8    /// `307 Temporary Redirect` (preserves HTTP method and body).
9    Temporary307,
10    /// `308 Permanent Redirect` (preserves HTTP method and body).
11    #[default]
12    Permanent308,
13}
14
15/// Action taken when a rewrite rule matches an incoming request path.
16#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
17pub enum RewriteAction {
18    /// Mutates `Request::set_path` internally and continues routing.
19    #[default]
20    InternalRewrite,
21    /// Short-circuits the pipeline with an HTTP redirect and `Location` header.
22    Redirect(RedirectStatus),
23}
24
25/// Trailing-slash normalization policy applied to non-root paths (`path != "/"`).
26#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
27pub enum TrailingSlashMode {
28    /// Leave trailing slashes untouched.
29    #[default]
30    Keep,
31    /// Remove trailing slashes (`/docs/` -> `/docs`).
32    Strip,
33    /// Ensure a trailing slash (`/docs` -> `/docs/`).
34    Enforce,
35}
36
37/// Outcome returned by [`CompiledRewrite::apply`] when evaluating a request context.
38#[derive(Clone, Debug, Eq, PartialEq)]
39pub enum RewriteOutcome {
40    /// No canonical redirect or rewrite rule matched (zero-allocation fast path).
41    Unchanged,
42    /// Request path was internally rewritten via `Request::set_path`.
43    Rewritten(String),
44    /// Response was populated with a redirect status and `Location` header ready to send.
45    Redirected {
46        /// HTTP redirect status code (`301`/`302`/`307`/`308`).
47        status_code: usize,
48        /// Target `Location` header value.
49        location: String,
50    },
51}
52
53/// Errors produced when compiling [`RewriteConfig`] into [`CompiledRewrite`].
54#[derive(Clone, Debug, Eq, PartialEq)]
55pub enum RewriteError {
56    /// A configured regex pattern failed to compile.
57    InvalidRegex {
58        /// Source pattern string.
59        pattern: String,
60        /// Underlying regex parser diagnostic.
61        message: String,
62    },
63    /// A configured canonical host or target contained forbidden CR/LF control characters.
64    UnsafeLocation(String),
65}