#[non_exhaustive]pub struct StackConfig {
pub timeout: Option<Duration>,
pub body_idle_timeout: Option<Duration>,
pub max_request_body_wire_bytes: Option<usize>,
pub max_request_body_decoded_bytes: Option<usize>,
pub load_shed: bool,
pub compression: Option<CompressionOptions>,
pub decompression: bool,
}Expand description
Tower stack configuration shared by [build_stack] and
[build_client_stack].
Each field is consumed by a dedicated apply_* factory in this module
(see [build_stack]’s body). Factories are no-ops when their field is
None/false, so toggling a field off produces a service whose
runtime shape is identical to the layer never having been built.
Composition uses the axum-style boxed-per-layer pattern: every
apply_* takes a [ServeService] and returns a [ServeService],
performing its own boxed_clone(). This re-erases the inner
Service::Future after each layer, so layer addition is decoupled
from the type-soup of Either<L::Service, S> and impl Layer<…>
return-position bound erasure (see Slice B (#184) carry-forward in
Slice C (#185)).
Slice D (#186): made public so the pure-Rust
crate::http::client::fetch_request can take &StackConfig directly.
#[non_exhaustive] so adapters constructing literal StackConfig
values (StackConfig { timeout, decompression, ..default() }) opt in
explicitly and future fields don’t break them.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.timeout: Option<Duration>Application execution timeout. None ⇒ no TimeoutLayer is applied.
body_idle_timeout: Option<Duration>Maximum time a request body may remain pending while it is actively
being consumed. None disables progress-based body protection.
max_request_body_wire_bytes: Option<usize>Maximum wire request body size before the server rejects with 413.
This limit is applied before decompression, i.e. it counts compressed
bytes as they arrive from the QUIC stream. It is an effective guard
against network-level DoS (high-bandwidth senders), but it does not
protect against a compression bomb (a small compressed body that
decompresses to many GB). Use Self::max_request_body_decoded_bytes
for that.
max_request_body_decoded_bytes: Option<usize>Maximum decoded request body size before the server rejects with 413.
This limit is applied after decompression. It is the primary guard against compression bombs: a zstd payload that is tiny on the wire but expands to GB in memory is rejected once the decoded byte count crosses this threshold. Transparent proxies normally leave this unset and let the application-facing server enforce its semantic decoded size.
load_shed: booltrue ⇒ wrap with LoadShedLayer so saturated capacity returns 503
immediately rather than blocking the caller.
compression: Option<CompressionOptions>Operator’s compression configuration. None disables response
compression on the server side; ignored by [build_client_stack]
(clients do not yet compress request bodies).
decompression: booltrue ⇒ apply RequestDecompressionLayer (server) /
DecompressionLayer (client). Defaults to true — every server
today accepts compressed requests, every client accepts compressed
responses.
Implementations§
Source§impl StackConfig
impl StackConfig
Sourcepub fn with_timeout(self, timeout: Option<Duration>) -> Self
pub fn with_timeout(self, timeout: Option<Duration>) -> Self
Set Self::timeout using the builder pattern.
Convenience constructor for external callers — #[non_exhaustive]
blocks struct-literal construction outside this crate, so use
StackConfig::default().with_timeout(...).
Sourcepub fn with_decompression(self, decompression: bool) -> Self
pub fn with_decompression(self, decompression: bool) -> Self
Set Self::decompression using the builder pattern.
Trait Implementations§
Source§impl Clone for StackConfig
impl Clone for StackConfig
Source§impl Debug for StackConfig
impl Debug for StackConfig
Auto Trait Implementations§
impl Freeze for StackConfig
impl RefUnwindSafe for StackConfig
impl Send for StackConfig
impl Sync for StackConfig
impl Unpin for StackConfig
impl UnsafeUnpin for StackConfig
impl UnwindSafe for StackConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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> ⓘ
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 more