simplify: unify route structs, fix prefix collision, lint fixes
- Unify RouteConfig/RouteEntry/RouteResponse into single RouteEntry - Fix prefix collision: /api no longer matches /apiary (segment boundary check) - Add path traversal rejection in route API - Extract MdnsAnnouncement struct (clippy type_complexity) - cargo fmt Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -24,11 +24,14 @@ impl ServiceEntry {
|
||||
/// Resolve backend port and (possibly rewritten) path for a request
|
||||
pub fn resolve_route(&self, request_path: &str) -> (u16, String) {
|
||||
// Longest prefix match
|
||||
let matched = self.routes.iter()
|
||||
let matched = self
|
||||
.routes
|
||||
.iter()
|
||||
.filter(|r| {
|
||||
request_path == r.path
|
||||
|| request_path.starts_with(&r.path)
|
||||
&& (r.path.ends_with('/') || request_path.as_bytes().get(r.path.len()) == Some(&b'/'))
|
||||
&& (r.path.ends_with('/')
|
||||
|| request_path.as_bytes().get(r.path.len()) == Some(&b'/'))
|
||||
})
|
||||
.max_by_key(|r| r.path.len());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user