Skip to main content

Router

Struct Router 

Source
pub struct Router {
    pub tree: TrieNode<Vec<(PathRule, MethodRule, Route)>>,
    /* private fields */
}

Fields§

§tree: TrieNode<Vec<(PathRule, MethodRule, Route)>>

Implementations§

Source§

impl Router

Source

pub fn new() -> Router

Source

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.

Source

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.

Source

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.

Source

pub fn remove_http_front( &mut self, front: &HttpFrontend, ) -> Result<(), RouterError>

Source

pub fn add_tree_rule( &mut self, hostname: &[u8], path: &PathRule, method: &MethodRule, cluster: &Route, ) -> bool

Source

pub fn remove_tree_rule( &mut self, hostname: &[u8], path: &PathRule, method: &MethodRule, ) -> bool

Source

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:

  1. Route::Frontend(rc) with inherits_listener_hsts == true: rebuild headers_response by dropping any existing Strict-Transport-Security entry and appending a freshly rendered one when new_hsts resolves to an enabled value (enabled = Some(true)). The existing operator Append/Set response headers stay in place.

  2. Route::ClusterId(id) and Route::Deny (lightweight “no policy” shapes): when new_hsts resolves to enabled, promote in place to a minimal Route::Frontend(rc) carrying just the HSTS edit on headers_response (and inherits_listener_hsts == true so 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. When new_hsts resolves 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.

Source

pub fn add_pre_rule( &mut self, domain: &DomainRule, path: &PathRule, method: &MethodRule, cluster_id: &Route, ) -> bool

Source

pub fn add_post_rule( &mut self, domain: &DomainRule, path: &PathRule, method: &MethodRule, cluster_id: &Route, ) -> bool

Source

pub fn remove_pre_rule( &mut self, domain: &DomainRule, path: &PathRule, method: &MethodRule, ) -> bool

Source

pub fn remove_post_rule( &mut self, domain: &DomainRule, path: &PathRule, method: &MethodRule, ) -> bool

Source

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.

Trait Implementations§

Source§

impl Default for Router

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more