pub struct PathRewriteFilter { /* private fields */ }Expand description
Rewrites the request path before forwarding to the upstream.
Supports three operations (one per filter instance):
strip_prefix: remove a leading path prefixadd_prefix: prepend a path prefixreplace: regex find/replace on the path
Query strings are preserved across all operations.
§YAML configuration
filter: path_rewrite
strip_prefix: "/api/v1"filter: path_rewrite
add_prefix: "/api/v1"filter: path_rewrite
replace:
pattern: "^/old/(.*)"
replacement: "/new/$1"§Example
ⓘ
use praxis_filter::PathRewriteFilter;
let yaml: serde_yaml::Value = serde_yaml::from_str(r#"strip_prefix: "/api/v1""#).unwrap();
let filter = PathRewriteFilter::from_config(&yaml).unwrap();
assert_eq!(filter.name(), "path_rewrite");Implementations§
Source§impl PathRewriteFilter
impl PathRewriteFilter
Sourcepub fn from_config(config: &Value) -> Result<Box<dyn HttpFilter>, FilterError>
pub fn from_config(config: &Value) -> Result<Box<dyn HttpFilter>, FilterError>
Create a path rewrite filter from parsed YAML config.
Exactly one of strip_prefix, add_prefix, or replace
must be specified.
§Errors
Returns FilterError if the config is invalid or the
regex pattern fails to compile.
§Example
ⓘ
use praxis_filter::PathRewriteFilter;
let yaml: serde_yaml::Value = serde_yaml::from_str(r#"add_prefix: "/v2""#).unwrap();
let filter = PathRewriteFilter::from_config(&yaml).unwrap();
assert_eq!(filter.name(), "path_rewrite");ⓘ
use praxis_filter::PathRewriteFilter;
let yaml: serde_yaml::Value = serde_yaml::from_str(
r#"
replace:
pattern: "^/old/(.*)"
replacement: "/new/$1"
"#,
)
.unwrap();
let filter = PathRewriteFilter::from_config(&yaml).unwrap();
assert_eq!(filter.name(), "path_rewrite");Trait Implementations§
Source§impl HttpFilter for PathRewriteFilter
impl HttpFilter for PathRewriteFilter
Source§fn name(&self) -> &'static str
fn name(&self) -> &'static str
Unique name identifying this filter type (e.g.
"router", "rate_limit").Source§fn on_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 mut HttpFilterContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<FilterAction, FilterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 mut HttpFilterContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<FilterAction, FilterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called for each incoming request, in pipeline order.
Source§fn on_response<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 mut HttpFilterContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<FilterAction, FilterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_response<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 mut HttpFilterContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<FilterAction, FilterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called for each response, in reverse pipeline order. Read more
Source§fn request_body_access(&self) -> BodyAccess
fn request_body_access(&self) -> BodyAccess
Declares what access this filter needs to request bodies. Read more
Source§fn response_body_access(&self) -> BodyAccess
fn response_body_access(&self) -> BodyAccess
Declares what access this filter needs to response bodies. Read more
Source§fn request_body_mode(&self) -> BodyMode
fn request_body_mode(&self) -> BodyMode
Declares the delivery mode for request body chunks. Read more
Source§fn response_body_mode(&self) -> BodyMode
fn response_body_mode(&self) -> BodyMode
Declares the delivery mode for response body chunks. Read more
Source§fn needs_request_context(&self) -> bool
fn needs_request_context(&self) -> bool
Whether this filter needs the original request context
during body phases. Read more
Source§fn apply_insecure_options(&self, _options: &InsecureOptions)
fn apply_insecure_options(&self, _options: &InsecureOptions)
Apply global
InsecureOptions to this filter. Read moreSource§fn compression_config(&self) -> Option<&CompressionConfig>
fn compression_config(&self) -> Option<&CompressionConfig>
Returns the compression configuration if this filter enables
response compression. Read more
Source§fn on_request_body<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
ctx: &'life1 mut HttpFilterContext<'life2>,
body: &'life3 mut Option<Bytes>,
end_of_stream: bool,
) -> Pin<Box<dyn Future<Output = Result<FilterAction, FilterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn on_request_body<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
ctx: &'life1 mut HttpFilterContext<'life2>,
body: &'life3 mut Option<Bytes>,
end_of_stream: bool,
) -> Pin<Box<dyn Future<Output = Result<FilterAction, FilterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Called for each chunk of request body data, in pipeline order. Read more
Source§fn on_response_body(
&self,
ctx: &mut HttpFilterContext<'_>,
body: &mut Option<Bytes>,
end_of_stream: bool,
) -> Result<FilterAction, FilterError>
fn on_response_body( &self, ctx: &mut HttpFilterContext<'_>, body: &mut Option<Bytes>, end_of_stream: bool, ) -> Result<FilterAction, FilterError>
Called for each chunk of response body data, in reverse
pipeline order. Read more
Auto Trait Implementations§
impl Freeze for PathRewriteFilter
impl RefUnwindSafe for PathRewriteFilter
impl Send for PathRewriteFilter
impl Sync for PathRewriteFilter
impl Unpin for PathRewriteFilter
impl UnsafeUnpin for PathRewriteFilter
impl UnwindSafe for PathRewriteFilter
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more