Trait ferrum::middleware::BeforeMiddleware
[−]
[src]
pub trait BeforeMiddleware: Send + Sync + 'static { fn before(&self, _request: &mut Request) -> FerrumResult<()> { ... } fn catch(
&self,
_request: &mut Request,
error: FerrumError
) -> FerrumResult<()> { ... } }
BeforeMiddleware
are fired before a Handler
is called inside of a Chain.
BeforeMiddleware
are responsible for doing request pre-processing that requires
the ability to change control-flow, such as authorization middleware, or for editing
the request by modifying the headers.
BeforeMiddleware
only have access to the Request, if you need to modify or read a Response,
you will need AfterMiddleware
. Middleware which wishes to send an early response that
is not an error cannot be BeforeMiddleware
, but should instead be AroundMiddleware
.
Provided Methods
fn before(&self, _request: &mut Request) -> FerrumResult<()>
Do whatever work this middleware should do with a Request
object.
fn catch(&self, _request: &mut Request, error: FerrumError) -> FerrumResult<()>
Respond to an error thrown by a previous BeforeMiddleware
.
Returning a Ok
will cause the request to resume the normal flow at the
next BeforeMiddleware
, or if this was the last BeforeMiddleware
, at the Handler
.
Implementations on Foreign Types
impl BeforeMiddleware for Box<BeforeMiddleware>
[src]
fn before(&self, req: &mut Request) -> FerrumResult<()>
[src]
fn catch(&self, req: &mut Request, err: FerrumError) -> FerrumResult<()>
[src]
impl<T> BeforeMiddleware for Arc<T> where
T: BeforeMiddleware,
[src]
T: BeforeMiddleware,