#[non_exhaustive]pub struct ClientConfig {
pub base_url: String,
pub timeout: Duration,
pub stream_idle_timeout: Duration,
pub retry: RetryConfig,
pub stream_reconnect: ReconnectConfig,
pub require_tls: bool,
pub pool_max_idle_per_host: usize,
pub pool_idle_timeout: Option<Duration>,
pub max_concurrent_requests: Option<usize>,
pub internal_token_provider: Option<InternalTokenProvider>,
}Expand description
Base configuration for a generated REST client.
#[non_exhaustive]: construct via ClientConfig::new and the with_*
chain rather than a struct literal, so future transport knobs can be added
without a breaking change.
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.base_url: StringBase URL prefix (e.g., https://billing.internal).
Combined with the base path declared in the projection trait.
timeout: DurationDeadline applied to a single unary attempt — NOT to the whole logical
call. A #[retryable] method may make up to retry.max_attempts attempts,
so the worst-case wall-clock for a logical call is bounded by
max_attempts × (timeout + retry.max_delay) (the per-retry backoff is
itself clamped to RetryConfig::max_delay, including a server-advised
Retry-After). There is deliberately no separate whole-call budget field.
stream_idle_timeout: DurationPer-item idle deadline for streams of any framing: the maximum gap
between two received wire chunks before the stream is treated as timed
out. A long-lived stream is NOT bounded by timeout
(which would kill a healthy slow stream); it is bounded by this larger
idle deadline instead. Defaults to 60s (> the unary default).
This is idle, not quiet: any wire chunk resets it, including ones that dispatch no item (an SSE keepalive comment, a multipart part header block arriving on its own).
retry: RetryConfigRetry policy applied to methods marked #[retryable].
stream_reconnect: ReconnectConfigReconnect policy for streams of any framing. By default
max_attempts: 0 — stream failures bubble up unchanged. Set explicitly
to opt into transparent re-open on a transient failure.
Two limits are deliberate rather than accidental:
- It applies only to a method whose open is immediate
(
#[streaming] fn). A fallible open (#[streaming] async fn) carries domain semantics the client must not blindly repeat — a re-open can collide with an exclusion lease the first open acquired, and its failure would land as a stream item, past the caller’s open-time error handling. Generated code therefore passesReconnectConfig::disabledfor a fallible open regardless of this value. - Resume via
Last-Event-IDis SSE-only. A reconnectedmultipart/mixedstream re-issues the original request with no resume token, because the framing has none. The transport still reopens it, but that is a blind restart, not a resume: the server replays the body from its first part, so any items already delivered before the failure are delivered again (at-least-once, with no marker for the restart). Enable reconnect for a multipart stream only where the consumer tolerates duplicates; one needing exactly-once must instead leave reconnect disabled and run its own reopen loop with application-level dedup.
require_tls: boolWhen true, the generated client refuses plaintext http:// and
requires TLS (toolkit_http::TransportSecurity::TlsOnly) for every
request — including the bearer-carrying Authorization header, which
otherwise would ride whatever scheme base_url uses. Defaults to
false, preserving the platform’s existing in-mesh service-to-service
convention where plaintext HTTP inside a secured network boundary is an
accepted, deliberate choice (see
build_default_http_client).
Set this when a resolved endpoint may cross an untrusted network. Read by
both the REST and gRPC transports.
pool_max_idle_per_host: usizeMaximum idle keep-alive connections retained per upstream host
(active in-flight requests are not capped). Defaults to 128; raise via
ClientTuning for higher concurrency.
REST transport only.
Keep it at or above the expected per-upstream concurrency: below that,
hyper closes excess connections as they idle and reopens them per
request, producing a connect(2) storm that dominates CPU. The 128
default clears the ~100-concurrent gear-to-gear traffic that motivated it
(the old toolkit-http default of 32 did not).
pool_idle_timeout: Option<Duration>How long an idle keep-alive connection is retained before it is closed —
the companion of pool_max_idle_per_host
(which bounds how many). Keep it above the gap between bursts to an
upstream so connections stay warm. Defaults to 90s. REST transport only.
None does not mean “kept indefinitely”: it leaves the hyper-util
setter unset, so hyper-util’s own default (~90s) applies. The default is
an explicit Some(90s) for that reason.
max_concurrent_requests: Option<usize>Maximum in-flight requests through this client at once (across all
upstream hosts). None disables the limiter; Some(n) caps at n, with
Some(0) clamped to 1 by the transport so the client can’t wedge
shedding everything. Defaults to Some(128), aligned with
pool_max_idle_per_host so the idle pool
is fully reusable before load is shed. REST transport only.
The cap bounds requests waiting on response headers — the tower permit
is released once headers arrive, so a long-lived SSE/multipart body holds
no slot while it streams; size it against in-flight requests, not open
streams. A shed request surfaces as
TransportError::Overloaded,
which is not transient, so a saturated client fails fast rather than
retrying into its own overload.
internal_token_provider: Option<InternalTokenProvider>Source of the platform-plane internal credential attached to methods
whose plane marker is PlatformSecurityContext (carried as
X-ToolKit-Internal-Token). None (the default) attaches nothing —
legitimate for Profile 1 / in-process (InternalCredential::None);
the requirement is enforced server-side. The bootstrap layer populates
this from the process’s selected InternalCredential. Tenant-plane
methods (SecurityContext) never consult it; they forward the caller’s
bearer token from the argument.
Implementations§
Source§impl ClientConfig
impl ClientConfig
Sourcepub fn new(base_url: impl Into<String>) -> ClientConfig
pub fn new(base_url: impl Into<String>) -> ClientConfig
Create a new config with sensible defaults.
Sourcepub fn with_timeout(self, timeout: Duration) -> ClientConfig
pub fn with_timeout(self, timeout: Duration) -> ClientConfig
Override the per-call (unary) timeout.
Sourcepub fn with_stream_idle_timeout(self, idle: Duration) -> ClientConfig
pub fn with_stream_idle_timeout(self, idle: Duration) -> ClientConfig
Override the per-item stream idle deadline (max gap between wire
chunks). See Self::stream_idle_timeout.
Sourcepub fn with_retry(self, retry: RetryConfig) -> ClientConfig
pub fn with_retry(self, retry: RetryConfig) -> ClientConfig
Override the retry policy.
Sourcepub fn with_stream_reconnect(
self,
stream_reconnect: ReconnectConfig,
) -> ClientConfig
pub fn with_stream_reconnect( self, stream_reconnect: ReconnectConfig, ) -> ClientConfig
Override the stream reconnect policy. Use
ReconnectConfig::disabled() to disable (the default) or
ReconnectConfig::enabled() to opt in. See
Self::stream_reconnect for what it does and does not govern.
Sourcepub fn with_require_tls(self, require_tls: bool) -> ClientConfig
pub fn with_require_tls(self, require_tls: bool) -> ClientConfig
Require TLS (reject plaintext http://) for this client. See
Self::require_tls.
Sourcepub fn with_pool_max_idle_per_host(self, max: usize) -> ClientConfig
pub fn with_pool_max_idle_per_host(self, max: usize) -> ClientConfig
Override the max idle keep-alive connections per upstream host. See
Self::pool_max_idle_per_host.
Sourcepub fn with_pool_idle_timeout(self, timeout: Option<Duration>) -> ClientConfig
pub fn with_pool_idle_timeout(self, timeout: Option<Duration>) -> ClientConfig
Override how long idle keep-alive connections are retained (None uses
hyper-util’s default). See Self::pool_idle_timeout.
Sourcepub fn with_max_concurrent_requests(self, max: Option<usize>) -> ClientConfig
pub fn with_max_concurrent_requests(self, max: Option<usize>) -> ClientConfig
Override the max concurrent in-flight requests (None disables the
limiter). See Self::max_concurrent_requests.
Sourcepub fn with_internal_token_provider(
self,
provider: impl Into<Option<InternalTokenProvider>>,
) -> ClientConfig
pub fn with_internal_token_provider( self, provider: impl Into<Option<InternalTokenProvider>>, ) -> ClientConfig
Set (or clear) the platform-plane internal-credential provider. See
Self::internal_token_provider. Accepts either an
InternalTokenProvider or an Option<InternalTokenProvider>, so the
bootstrap layer can pass through whatever the process selected without a
branch.
Trait Implementations§
Source§impl Clone for ClientConfig
impl Clone for ClientConfig
Source§fn clone(&self) -> ClientConfig
fn clone(&self) -> ClientConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ClientConfig
impl !UnwindSafe for ClientConfig
impl Freeze for ClientConfig
impl Send for ClientConfig
impl Sync for ClientConfig
impl Unpin for ClientConfig
impl UnsafeUnpin for ClientConfig
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt 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,
Source§fn decompression(self) -> Decompression<Self>where
Self: Sized,
fn decompression(self) -> Decompression<Self>where
Self: Sized,
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,
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,
Source§fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
Source§fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
Source§fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
x-request-id as the header name. Read moreSource§fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
Source§fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
x-request-id as the header name. Read moreSource§fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>where
Self: Sized,
fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>where
Self: Sized,
500 Internal Server responses. Read moreSource§fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
413 Payload Too Large responses. Read moreSource§impl<T> WithSecurityContext for T
impl<T> WithSecurityContext for T
Source§fn security_ctx<'a>(&'a self, ctx: &'a SecurityContext) -> Secured<'a, T>where
T: Sized,
fn security_ctx<'a>(&'a self, ctx: &'a SecurityContext) -> Secured<'a, T>where
T: Sized,
Secured wrapper. Read more