pub struct TowerLayer<L> { /* private fields */ }Available on crate feature
tower only.Expand description
A Tower Layer — tower-http’s
SetResponseHeaderLayer, ValidateRequestHeaderLayer, TimeoutLayer,
NormalizePathLayer, … — as rws Middleware: app.wrap(TowerLayer::new(layer)).
Per request the layer wraps the rest of the stack (Next); the request
goes in as http::Request<Body> and the response comes back through the
layer as http::Response<_>. Streamed responses (files, SSE, proxied
streams) stay streams. Request bodies reach the layer read into memory.
It runs on a blocking-pool thread, never inline on the event loop.
Implementations§
Source§impl<L> TowerLayer<L>
impl<L> TowerLayer<L>
pub fn new(layer: L) -> TowerLayer<L>
Trait Implementations§
Source§impl<L, ResBody> Middleware for TowerLayer<L>where
L: for<'a> Layer<Next<'a>> + Send + Sync,
<L as Layer<Next<'a>>>::Service: for<'a> Service<Request<Body>, Response = Response<ResBody>>,
<<L as Layer<Next<'a>>>::Service as Service<Request<Body>>>::Error: for<'a> Into<Box<dyn Error + Send + Sync>>,
ResBody: Body<Data = Bytes> + Send + 'static,
<ResBody as Body>::Error: Into<Box<dyn Error + Send + Sync>>,
impl<L, ResBody> Middleware for TowerLayer<L>where
L: for<'a> Layer<Next<'a>> + Send + Sync,
<L as Layer<Next<'a>>>::Service: for<'a> Service<Request<Body>, Response = Response<ResBody>>,
<<L as Layer<Next<'a>>>::Service as Service<Request<Body>>>::Error: for<'a> Into<Box<dyn Error + Send + Sync>>,
ResBody: Body<Data = Bytes> + Send + 'static,
<ResBody as Body>::Error: Into<Box<dyn Error + Send + Sync>>,
fn handle( &self, request: &Request, connection: &ConnectionInfo, next: &dyn Application, ) -> Result<Response, String>
Source§fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
true when this layer’s own work for request never blocks (in-memory
state, atomics, short mutexes) — see Application::runs_inline. A
WithMiddleware stack runs inline only if every layer and the inner
application agree. Default false.Source§fn is_passthrough(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn is_passthrough( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when handle would do nothing for request but call next
(e.g. a rate limit that isn’t configured). A WithMiddleware stack
offers the inner application’s execute_async only if every layer
passes the request through. Default false.Source§fn accepts_streamed_body(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn accepts_streamed_body( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when this layer never reads request.body, so the inner
application may receive it as a stream (Application::streams_body).
A layer that inspects the body (CSRF tokens in a form, request
signatures, rewriting) must keep the default false: it would see an
empty body.Source§fn answers_streamed_body(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn answers_streamed_body( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when this layer answers request itself — it doesn’t call
next — and reads its body as a stream (a proxy forwarding it as it
arrives). The body is then streamed whatever the layers after it and
the application would say. Requires accepts_streamed_body. Since
18.3.0.Source§fn layer_name(&self) -> &'static str
fn layer_name(&self) -> &'static str
A short name for this layer, as tools that describe an app list it
(
Application::middleware_names): by default the type’s name
without its module path or generic parameters (CacheLayer). Since
18.28.0.Auto Trait Implementations§
impl<L> Freeze for TowerLayer<L>where
L: Freeze,
impl<L> RefUnwindSafe for TowerLayer<L>where
L: RefUnwindSafe,
impl<L> Send for TowerLayer<L>where
L: Send,
impl<L> Sync for TowerLayer<L>where
L: Sync,
impl<L> Unpin for TowerLayer<L>where
L: Unpin,
impl<L> UnsafeUnpin for TowerLayer<L>where
L: UnsafeUnpin,
impl<L> UnwindSafe for TowerLayer<L>where
L: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ServiceExt for T
impl<T> ServiceExt for T
Source§fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>where
Self: Sized,
Available on crate feature
map-response-body only.Apply a transformation to the response body. Read more
Source§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
Available on crate feature
trace only.High level tracing that classifies responses using HTTP status codes. Read more
Source§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
Available on crate feature
trace only.High level tracing that classifies responses using gRPC headers. Read more