Skip to main content

MiddlewareScope

Struct MiddlewareScope 

Source
pub struct MiddlewareScope { /* private fields */ }
Expand description

Selects the requests one registered middleware layer observes.

An empty scope matches every request, which is what HttpApp::with_middleware registers. Path prefixes and operation predicates combine as AND between the two categories and OR inside one category.

The selected operation is unknown before routing, so a scope that declares an operation predicate never matches HttpMiddleware::on_request; that layer sees HttpMiddleware::on_operation and HttpMiddleware::on_response instead. A layer whose scope does not match is also not counted by the security guard, so a scoped verifier cannot silently authorize an operation outside its subtree.

Implementations§

Source§

impl MiddlewareScope

Source

pub const fn all() -> Self

A scope that constrains nothing.

Source

pub fn prefix(prefix: &str) -> Self

A scope limited to one path prefix.

Source

pub fn operation(operation_id: &str) -> Self

A scope limited to one operation id.

Source

pub fn with_prefix(self, prefix: &str) -> Self

Adds an accepted path prefix, matched on segment boundaries.

/ingest matches /ingest and /ingest/events, never /ingested.

Source

pub fn with_operation(self, operation_id: &str) -> Self

Adds one accepted operation id.

Source

pub fn with_operation_prefix(self, prefix: &str) -> Self

Adds an accepted operation id prefix, for id namespaces such as ingest..

Source

pub fn with_operation_filter<Filter>(self, filter: Filter) -> Self
where Filter: Fn(&str) -> bool + 'static,

Adds an operation id predicate for a selection the other constraints cannot express.

Source

pub fn is_global(&self) -> bool

Returns whether this scope constrains nothing.

Source

pub fn matches_request(&self, path: &str) -> bool

Matches before routing, when only the request path is known.

Source

pub fn matches_operation(&self, path: &str, operation_id: &str) -> bool

Matches after routing, when the selected operation is known.

Trait Implementations§

Source§

impl Clone for MiddlewareScope

Source§

fn clone(&self) -> MiddlewareScope

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MiddlewareScope

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MiddlewareScope

Source§

fn default() -> MiddlewareScope

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<T> BackgroundExt for T

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ResponseExt for T

Source§

fn header( self, name: impl Into<String>, value: impl Into<String>, ) -> WithHeaders<Self>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.