zng_task::http

Struct ClientBuilder

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

Builder that can be used to create a Client.

Use Client::builder to start building.

§Examples

use zng_task::http::*;

let client = Client::builder().metrics(true).build();

Implementations§

source§

impl ClientBuilder

source

pub fn new() -> Self

New default builder.

source

pub fn build(self) -> Client

Build the Client using the configured options.

source

pub fn build_custom<F>(self, custom: F) -> Result<Client, Error>
where F: FnOnce(HttpClientBuilder) -> Result<HttpClient, Error>,

Build the client with more custom build calls in the inner builder.

source

pub fn default_header( self, key: impl TryHeaderName, value: impl TryHeaderValue, ) -> Result<Self, Error>

Add a default header to be passed with every request.

source

pub fn cookies(self) -> Self

Enable persistent cookie handling for all requests using this client using a shared cookie jar.

source

pub fn cookie_jar(self, cookie_jar: CookieJar) -> Self

Set a cookie jar to use to accept, store, and supply cookies for incoming responses and outgoing requests.

Note that the default_client already has a cookie jar.

source

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

Specify a maximum amount of time that a complete request/response cycle is allowed to take before being aborted. This includes DNS resolution, connecting to the server, writing the request, and reading the response.

Note that this includes the response read operation, so if you get a response but don’t read-it within this timeout you will get a TimedOut IO error.

By default no timeout is used.

source

pub fn connect_timeout(self, timeout: Duration) -> Self

Set a timeout for establishing connections to a host.

If not set, the default_client default of 90 seconds will be used.

source

pub fn low_speed_timeout(self, low_speed: u32, timeout: Duration) -> Self

Specify a maximum amount of time where transfer rate can go below a minimum speed limit.

The low_speed limit is in bytes/s. No low-speed limit is configured by default.

source

pub fn redirect_policy(self, policy: RedirectPolicy) -> Self

Set a policy for automatically following server redirects.

If enabled the “Referer” header will be set automatically too.

source

pub fn auto_decompress(self, enabled: bool) -> Self

Enable or disable automatic decompression of the response body.

If enabled the “Accept-Encoding” will also be set automatically, if it was not set using default_header.

This is enabled by default.

source

pub fn max_upload_speed(self, max: u64) -> Self

Set a maximum upload speed for the request body, in bytes per second.

source

pub fn max_download_speed(self, max: u64) -> Self

Set a maximum download speed for the response body, in bytes per second.

source

pub fn metrics(self, enable: bool) -> Self

Enable or disable metrics collecting.

When enabled you can get the information using the Response::metrics method.

This is enabled by default.

source

pub fn cache(self, cache: impl CacheDb) -> Self

Sets the CacheDb to use.

Caching is only enabled if there is a DB, no caching is done by default.

source

pub fn cache_mode( self, selector: impl Fn(&Request) -> CacheMode + Send + Sync + 'static, ) -> Self

Sets the CacheMode selector.

The selector closure is called for every cacheable request before it is made, it must return a CacheMode value that configures how the cache is used.

Note that the closure is only called if a cache is set.

Trait Implementations§

source§

impl Default for ClientBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.

§

impl<T> Instrument for T

§

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

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
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
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T

source§

impl<T> StateValue for T
where T: Any + Send + Sync,