pub struct RouterFilter { /* private fields */ }Expand description
Routes requests to clusters based on path prefix and host header.
If a preceding filter (such as path_rewrite or url_rewrite) has
set rewritten_path, the router matches against the rewritten
path. Otherwise, it uses the original request path.
Sets ctx.cluster for downstream filters but does not pick an
endpoint or forward the request. The load_balancer filter reads
ctx.cluster to select an endpoint.
Longest prefix wins. Routes without host match any host. Header
restrictions use AND semantics with case-sensitive matching.
§YAML configuration
filter: router
routes:
- path_prefix: "/"
cluster: default§Example
use praxis_filter::RouterFilter;
let yaml: serde_yaml::Value = serde_yaml::from_str(
r#"
routes:
- path_prefix: "/"
cluster: default
"#,
)
.unwrap();
let filter = RouterFilter::from_config(&yaml).unwrap();
assert_eq!(filter.name(), "router");Implementations§
Source§impl RouterFilter
impl RouterFilter
Sourcepub fn new(routes: Vec<Route>) -> Result<Self, FilterError>
pub fn new(routes: Vec<Route>) -> Result<Self, FilterError>
Create a router from a list of routes with default alias options.
Path prefix matching uses segment-boundary semantics per Gateway API:
/api matches /api, /api/, /api/v1 but NOT /apikeys.
Trailing slashes on prefixes are ignored (/api is equivalent to /api/).
use praxis_core::config::{PathMatch, Route};
use praxis_filter::RouterFilter;
let router = RouterFilter::new(vec![
Route {
path_match: PathMatch::Prefix {
path_prefix: "/".to_owned(),
},
host: None,
headers: None,
cluster: "default".into(),
},
Route {
path_match: PathMatch::Prefix {
path_prefix: "/api".to_owned(),
},
host: None,
headers: None,
cluster: "api".into(),
},
])
.unwrap();§Errors
Returns FilterError if alias configuration is invalid.
Sourcepub fn with_multi_level_subdomain_matching(self, enabled: bool) -> Self
pub fn with_multi_level_subdomain_matching(self, enabled: bool) -> Self
Enable multi-level subdomain matching for wildcard hosts.
By default, *.example.com matches only foo.example.com.
When enabled, it also matches foo.bar.example.com (suffix
match), as required by Gateway API.
Sourcepub fn from_config(config: &Value) -> Result<Box<dyn HttpFilter>, FilterError>
pub fn from_config(config: &Value) -> Result<Box<dyn HttpFilter>, FilterError>
Create a router from parsed YAML config.
§Errors
Returns FilterError if route YAML is invalid or routes fail validation.
Trait Implementations§
Source§impl Debug for RouterFilter
impl Debug for RouterFilter
Source§impl HttpFilter for RouterFilter
impl HttpFilter for RouterFilter
Source§fn name(&self) -> &'static str
fn name(&self) -> &'static str
"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,
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,
Source§fn request_body_access(&self) -> BodyAccess
fn request_body_access(&self) -> BodyAccess
Source§fn response_body_access(&self) -> BodyAccess
fn response_body_access(&self) -> BodyAccess
Source§fn request_body_mode(&self) -> BodyMode
fn request_body_mode(&self) -> BodyMode
Source§fn response_body_mode(&self) -> BodyMode
fn response_body_mode(&self) -> BodyMode
Source§fn needs_request_context(&self) -> bool
fn needs_request_context(&self) -> bool
Source§fn apply_insecure_options(&self, _options: &InsecureOptions)
fn apply_insecure_options(&self, _options: &InsecureOptions)
InsecureOptions to this filter. Read more