Skip to main content

ClientBuilder

Struct ClientBuilder 

Source
pub struct ClientBuilder { /* private fields */ }
Expand description

How a Client is put together: credentials, the HTTP client, the retry budget, the cache and the hooks, each with a default a caller can move.

Implementations§

Source§

impl ClientBuilder

Source

pub fn new(config: Config) -> ClientBuilder

A builder for config, at the defaults and without credentials.

Source

pub fn token_provider( self, provider: impl TokenProvider + 'static, ) -> ClientBuilder

Authenticates with a bearer token drawn from provider for each request.

Source

pub fn auth_strategy( self, strategy: impl AuthStrategy + 'static, ) -> ClientBuilder

Authenticates however strategy does: the way in for anything but a bearer token.

Source

pub fn http_client(self, http: impl HttpClient + 'static) -> ClientBuilder

Replaces the HTTP client every request goes out on, including the attachment bytes that go to the storage service. The one supplied must not follow redirects; see HttpClient. The timeout set on the builder is then ignored — a timeout belongs to the client that can enforce it.

Source

pub fn user_agent(self, user_agent: impl Into<String>) -> ClientBuilder

What the client calls itself in User-Agent.

Source

pub fn timeout(self, timeout: Duration) -> ClientBuilder

How long the HTTP client the SDK ships gives an answer to arrive. It has no effect on one supplied with ClientBuilder::http_client. This bounds one request on the wire; the whole of an operation is bounded by ClientBuilder::operation_timeout.

Source

pub fn operation_timeout(self, limit: Duration) -> ClientBuilder

The most an operation may take from the call to its answer, everything the client waits for included: waiting at the gate, fetching credentials, every attempt, every wait between them, the resend after a refresh, and reading the body. Past it the operation ends as a retryable network error, and whatever it was doing is dropped — a permit it held goes back, and the hooks hear it end. Decoding the answer into the caller’s type comes after, on the caller’s own thread, and is not waited for. None by default: an operation may then take as long as its attempts and waits add up to, each attempt bounded only by the HTTP client’s own ClientBuilder::timeout.

Source

pub fn max_retries(self, max_retries: u32) -> ClientBuilder

The most times any operation is resent after a transient failure. A modelled route is resent as many times as its own policy allows and no more; this only lowers that. A path the caller wrote, which no policy covers, is resent this many times when its method is idempotent.

Source

pub fn base_delay(self, base_delay: Duration) -> ClientBuilder

The least the client waits before the first resend. A modelled route starts from the delay its own policy names when that is longer; a path the caller wrote starts from this, or from DEFAULT_BASE_DELAY when it is not set. Each wait after the first is double the one before. ClientBuilder::max_delay holds every wait down, this one included.

Source

pub fn max_delay(self, max_delay: Duration) -> ClientBuilder

The most the client waits between attempts, jitter included, whatever the policy, the backoff or ClientBuilder::base_delay asks for. The wait a Retry-After names is honoured as given.

Source

pub fn max_jitter(self, max_jitter: Duration) -> ClientBuilder

The most added at random to each wait, so resends from many clients do not land together.

Source

pub fn max_pages(self, max_pages: usize) -> ClientBuilder

How many pages Client::each_page reads before it stops. Zero is refused by ClientBuilder::build.

Source

pub fn max_response_body_bytes(self, bytes: usize) -> ClientBuilder

The most a JSON or HTML answer may deliver before the client refuses to hold it. Zero asks for the default: the cap cannot be lifted, only moved.

Source

pub fn cache(self, cache: impl ResponseCache + 'static) -> ClientBuilder

Caches JSON reads by ETag. Without this, config.cache_enabled decides whether a FileCache in config.cache_dir is used.

Source

pub fn hooks(self, hooks: impl Hooks + 'static) -> ClientBuilder

Reports every operation and every request the client makes. Several sets of hooks go on as one with crate::observability::ChainHooks.

Source

pub fn build(self) -> Result<Client, Error>

The client, or a usage error for a builder without credentials, with no timeout, or with no pages to read.

Source§

impl ClientBuilder

Source

pub fn resilience(self, config: ResilienceConfig) -> ClientBuilder

Installs the layers the config asks for, keeping whatever hooks the builder already carries: they still hear about every operation and request.

Source

pub fn circuit_breaker(self, config: CircuitBreakerConfig) -> ClientBuilder

Installs the circuit breaker alone.

Source

pub fn bulkhead(self, config: BulkheadConfig) -> ClientBuilder

Installs the bulkhead alone.

Source

pub fn rate_limit(self, config: RateLimitConfig) -> ClientBuilder

Installs the rate limiter alone.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more