pub struct Router {
pub tree: TrieNode<Vec<(PathRule, MethodRule, Route)>>,
/* private fields */
}Fields§
§tree: TrieNode<Vec<(PathRule, MethodRule, Route)>>Implementations§
Source§impl Router
impl Router
pub fn new() -> Router
Sourcepub fn lookup(
&self,
hostname: &str,
path: &str,
method: &Method,
) -> Result<RouteResult, RouterError>
pub fn lookup( &self, hostname: &str, path: &str, method: &Method, ) -> Result<RouteResult, RouterError>
Resolve a request to a RouteResult.
Looks up (hostname, path, method) against the pre, tree, and post
rule lists. The matched Route is converted into a RouteResult:
legacy variants (Route::ClusterId, Route::Deny) synthesize a
minimal RouteResult so existing call sites keep working, while
Route::Frontend runs the full Frontend → RouteResult pipeline,
substituting host/path captures into RewriteParts templates.
Sourcepub fn add_http_front(
&mut self,
front: &HttpFrontend,
) -> Result<(), RouterError>
pub fn add_http_front( &mut self, front: &HttpFrontend, ) -> Result<(), RouterError>
Add an HTTP/HTTPS frontend whose hsts field (if any) came from
the per-frontend configuration directly. Equivalent to
Self::add_http_front_with_hsts_origin called with
HstsOrigin::Explicit. The default for callers that don’t
know about listener-default inheritance — e.g. plain HTTP
listeners (HttpListenerConfig has no HSTS field) and tests.
Sourcepub fn add_http_front_with_hsts_origin(
&mut self,
front: &HttpFrontend,
hsts_origin: HstsOrigin,
) -> Result<(), RouterError>
pub fn add_http_front_with_hsts_origin( &mut self, front: &HttpFrontend, hsts_origin: HstsOrigin, ) -> Result<(), RouterError>
Add an HTTP/HTTPS frontend, recording whether the resolved
front.hsts was inherited from the listener default. The
inheritance bit is preserved on the resulting Frontend so a
later UpdateHttpsListenerConfig.hsts patch can reflow the new
default onto inheriting entries without disturbing explicit
per-frontend overrides.
pub fn remove_http_front( &mut self, front: &HttpFrontend, ) -> Result<(), RouterError>
pub fn add_tree_rule( &mut self, hostname: &[u8], path: &PathRule, method: &MethodRule, cluster: &Route, ) -> bool
pub fn remove_tree_rule( &mut self, hostname: &[u8], path: &PathRule, method: &MethodRule, ) -> bool
Sourcepub fn refresh_inheriting_hsts(
&mut self,
new_hsts: Option<&HstsConfig>,
) -> usize
pub fn refresh_inheriting_hsts( &mut self, new_hsts: Option<&HstsConfig>, ) -> usize
Walk every route and re-materialise the response-side HSTS edit
on frontends that inherited from the listener default. Operator
per-frontend HSTS overrides (inherits_listener_hsts == false)
are left untouched.
Called from lib/src/https.rs::HttpsListener::update_config when
an UpdateHttpsListenerConfig.hsts patch is applied.
Two refresh paths:
-
Route::Frontend(rc)withinherits_listener_hsts == true: rebuildheaders_responseby dropping any existingStrict-Transport-Securityentry and appending a freshly rendered one whennew_hstsresolves to an enabled value (enabled = Some(true)). The existing operatorAppend/Setresponse headers stay in place. -
Route::ClusterId(id)andRoute::Deny(lightweight “no policy” shapes): whennew_hstsresolves to enabled, promote in place to a minimalRoute::Frontend(rc)carrying just the HSTS edit onheaders_response(andinherits_listener_hsts == trueso subsequent patches keep refreshing the entry). Routing semantics are preserved — the promoted Frontend forwards / denies identically to the original variant — and the promoted entry now participates in path 1 on every later patch. Whennew_hstsresolves to “no HSTS” (None / disabled), lightweight routes are left untouched (no allocation is created just to hold an empty HSTS edit).
Path 2 fixes the case where a frontend was added without any
per-frontend policy field (the routing fast path stores it as
Route::ClusterId / Route::Deny, NOT Route::Frontend). Before
this two-path walk, listener-default HSTS patches silently
skipped every such “no-policy” frontend — which on a typical
Clever Cloud cleverapps.io shared listener was 99 % of the
frontends.
Returns the number of frontends touched. For path 1, refreshed
frontends where the new policy resolves to “no HSTS” are still
counted (the existing HSTS edit is stripped). For path 2, only
frontends actually promoted (i.e. new_hsts enabled) are
counted, since “no HSTS” is a no-op on the lightweight shape.
pub fn add_pre_rule( &mut self, domain: &DomainRule, path: &PathRule, method: &MethodRule, cluster_id: &Route, ) -> bool
pub fn add_post_rule( &mut self, domain: &DomainRule, path: &PathRule, method: &MethodRule, cluster_id: &Route, ) -> bool
pub fn remove_pre_rule( &mut self, domain: &DomainRule, path: &PathRule, method: &MethodRule, ) -> bool
pub fn remove_post_rule( &mut self, domain: &DomainRule, path: &PathRule, method: &MethodRule, ) -> bool
Sourcepub fn has_hostname(&self, hostname: &str) -> bool
pub fn has_hostname(&self, hostname: &str) -> bool
Returns true if any route (pre, tree, or post) references the given hostname.
This is used after removing a frontend to decide whether the hostname’s tags should be cleaned up. Tags must only be removed when no routes remain.