Expand description
Middleware implementations.
Middleware: the core Middleware trait + ClientWithMiddleware
chain runner, plus the bundled feature-gated implementations.
§Ordering semantics
Middleware wrap the transport in an onion; the middleware registered first is the outermost layer — it observes the request first and the response last:
ClientBuilder::new(client)
.with(AuthMiddleware) // 1st registered → outermost
.with(RetryMiddleware::new(config))
.build();
request → Auth → Retry → transport
response ← Auth ← Retry ← ╹Inner middleware therefore see every attempt a retry-style outer
middleware issues, and outer middleware see only the final outcome.
The built-in default client composes [retry, breaker]: the breaker
sits inside the retry loop and records each HTTP attempt
individually.
§Built-ins vs middleware (the composition story)
The bundled middleware are the composition points; the
crate::ClientBuilder knobs are the defaults:
| Knob (default) | Middleware equivalent (composable) |
|---|---|
retries / retry_bounds | RetryMiddleware (feature retry, default-on) |
with_breaker | CircuitBreakerMiddleware (feature circuit-breaker) |
| — | ThrottleMiddleware (feature throttle) |
| — | TimeoutMiddleware (feature timeout) |
base_url (eager) | BaseUrlMiddleware (feature base-url) |
crate::ClientBuilder::with_middleware registers custom middleware
outermost — wrapping the built-ins — so user middleware observe the
final outcome of the whole default stack.
Structs§
- Client
Builder - Builder for
ClientWithMiddleware: wrap areqwest::Clientwith middleware, first-registered = outermost. - Client
With Middleware - A
reqwest::Clientwrapped in a middleware chain. - Next
- The continuation passed to
Middleware::handle. - Request
Builder - A request builder bound to a
ClientWithMiddleware. - Retry
Config - Configuration for retry behavior.
- Retry
Middleware - Retry middleware wrapping the remainder of the chain in the estate’s
loop-retrybackoff loop.
Enums§
- Error
- Error type produced by the middleware stack.
Traits§
- Middleware
- Async middleware that wraps a
ClientWithMiddleware.
Functions§
- is_
retryable_ error - Whether
erris retried byRetryMiddleware: transport-level timeouts and connection failures. Middleware errors are permanent by design — a short-circuit (e.g. an open circuit breaker) must not be masked by retries. - is_
retryable_ status - Whether
statusis retried byRetryMiddleware: 408 Request Timeout, 429 Too Many Requests, and 5xx except 501 Not Implemented.
Type Aliases§
- Result
- Result alias used throughout the middleware stack.