pub struct WithMiddleware<A> { /* private fields */ }Expand description
An Application that applies a stack of Middleware layers before
dispatching to an inner application.
Layers are applied in registration order: the first .wrap()ed middleware
runs first on the request path and last on the response path.
Implementations§
Source§impl<A> WithMiddleware<A>where
A: Application,
impl<A> WithMiddleware<A>where
A: Application,
Sourcepub fn new(app: A) -> WithMiddleware<A>
pub fn new(app: A) -> WithMiddleware<A>
Wrap app with no initial middleware.
Sourcepub fn wrap(self, layer: impl Middleware + 'static) -> WithMiddleware<A>
pub fn wrap(self, layer: impl Middleware + 'static) -> WithMiddleware<A>
Add a middleware layer. Layers run in registration order.
Trait Implementations§
Source§impl<A> Application for WithMiddleware<A>where
A: Application,
impl<A> Application for WithMiddleware<A>where
A: Application,
Source§fn execute(
&self,
request: &Request,
connection: &ConnectionInfo,
) -> Result<Response, String>
fn execute( &self, request: &Request, connection: &ConnectionInfo, ) -> Result<Response, String>
Receives a parsed request and returns a fully-built response.
Walk your controller list with
is_matching / process and return the first match.Source§fn runs_inline(&self, request: &Request, connection: &ConnectionInfo) -> bool
fn runs_inline(&self, request: &Request, connection: &ConnectionInfo) -> bool
true when executing request is quick and never waits on anything
but the local filesystem — health checks, metrics, small static files.
The async servers (HTTP/1.1, HTTP/2, HTTP/3) then call execute
directly on the event loop, as nginx does, instead of handing the
request to tokio’s blocking pool: that handoff (a shared lock and two
cross-thread wake-ups) costs more than serving a small file. Read moreSource§fn execute_async<'a>(
&'a self,
request: &'a Request,
connection: &'a ConnectionInfo,
) -> Option<Pin<Box<dyn Future<Output = Result<Response, String>> + Send + 'a>>>
fn execute_async<'a>( &'a self, request: &'a Request, connection: &'a ConnectionInfo, ) -> Option<Pin<Box<dyn Future<Output = Result<Response, String>> + Send + 'a>>>
An asynchronous version of
execute for this request, when the
application has one: the async servers await it on the connection’s
task instead of tying up a blocking-pool thread while it waits (the
config-driven proxy uses this to wait for a backend without holding a
thread). None (the default) means “use execute”. Wrappers return
Some only when they add no synchronous work of their own.Source§fn streams_body(&self, request: &Request, connection: &ConnectionInfo) -> bool
fn streams_body(&self, request: &Request, connection: &ConnectionInfo) -> bool
true to receive this request’s body as a stream (Body::Stream)
instead of read into memory first: execute then runs while the
body is still arriving, on a blocking-pool thread, and reads it with
std::io::Read — a multi-gigabyte upload in a few chunks of memory.
Asked after the head is read, so request.body is empty here;
decide from the method, path and headers. Read moreSource§impl<A> Clone for WithMiddleware<A>where
A: Clone,
impl<A> Clone for WithMiddleware<A>where
A: Clone,
Source§fn clone(&self) -> WithMiddleware<A>
fn clone(&self) -> WithMiddleware<A>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<A> !RefUnwindSafe for WithMiddleware<A>
impl<A> !UnwindSafe for WithMiddleware<A>
impl<A> Freeze for WithMiddleware<A>where
A: Freeze,
impl<A> Send for WithMiddleware<A>where
A: Send,
impl<A> Sync for WithMiddleware<A>where
A: Sync,
impl<A> Unpin for WithMiddleware<A>where
A: Unpin,
impl<A> UnsafeUnpin for WithMiddleware<A>where
A: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more