Struct awc::ClientBuilder

source ·
pub struct ClientBuilder<S = (), M = ()> { /* private fields */ }
Expand description

An HTTP Client builder

This type can be used to construct an instance of Client through a builder-like pattern.

Implementations§

source§

impl ClientBuilder

source§

impl<S, Io, M> ClientBuilder<S, M>where S: Service<ConnectInfo<Uri>, Response = TcpConnection<Uri, Io>, Error = TcpConnectError> + Clone + 'static, Io: ActixStream + Debug + 'static,

source

pub fn connector<S1, Io1>(self, connector: Connector<S1>) -> ClientBuilder<S1, M>where S1: Service<ConnectInfo<Uri>, Response = TcpConnection<Uri, Io1>, Error = TcpConnectError> + Clone + 'static, Io1: ActixStream + Debug + 'static,

Use custom connector service.

source

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

Set request timeout

Request timeout is the total time before a response must be received. Default value is 5 seconds.

source

pub fn disable_timeout(self) -> Self

Disable request timeout.

source

pub fn local_address(self, addr: IpAddr) -> Self

Set local IP Address the connector would use for establishing connection.

source

pub fn max_http_version(self, val: Version) -> Self

Maximum supported HTTP major version.

Supported versions are HTTP/1.1 and HTTP/2.

source

pub fn disable_redirects(self) -> Self

Do not follow redirects.

Redirects are allowed by default.

source

pub fn max_redirects(self, num: u8) -> Self

Set max number of redirects.

Max redirects is set to 10 by default.

source

pub fn initial_window_size(self, size: u32) -> Self

Indicates the initial window size (in octets) for HTTP2 stream-level flow control for received data.

The default value is 65,535 and is good for APIs, but not for big objects.

source

pub fn initial_connection_window_size(self, size: u32) -> Self

Indicates the initial window size (in octets) for HTTP2 connection-level flow control for received data.

The default value is 65,535 and is good for APIs, but not for big objects.

source

pub fn no_default_headers(self) -> Self

Do not add fundamental default request headers.

By default Date and User-Agent headers are set.

source

pub fn add_default_header(self, header: impl TryIntoHeaderPair) -> Self

Add default header.

Headers added by this method get added to every request unless overridden by other methods.

Panics

Panics if header name or value is invalid.

source

pub fn basic_auth<N>(self, username: N, password: Option<&str>) -> Selfwhere N: Display,

Set client wide HTTP basic authorization header

source

pub fn bearer_auth<T>(self, token: T) -> Selfwhere T: Display,

Set client wide HTTP bearer authentication header

source

pub fn wrap<S1, M1>( self, mw: M1 ) -> ClientBuilder<S, NestTransform<M, M1, S1, ConnectRequest>>where M: Transform<S1, ConnectRequest>, M1: Transform<M::Transform, ConnectRequest>,

Registers middleware, in the form of a middleware component (type), that runs during inbound and/or outbound processing in the request life-cycle (request -> response), modifying request/response as necessary, across all requests managed by the Client.

source

pub fn finish(self) -> Clientwhere M: Transform<DefaultConnector<ConnectorServicePriv<TcpConnectorService<TcpConnectorInnerService<S>>, Rc<dyn Service<Connect, Response = (Box<dyn ConnectionIo>, Protocol), Error = ConnectError, Future = LocalBoxFuture<'static, Result<(Box<dyn ConnectionIo>, Protocol), ConnectError>>>>, Io, Box<dyn ConnectionIo>>>, ConnectRequest> + 'static, M::Transform: Service<ConnectRequest, Response = ConnectResponse, Error = SendRequestError>,

Finish build process and create Client instance.

Auto Trait Implementations§

§

impl<S = (), M = ()> !RefUnwindSafe for ClientBuilder<S, M>

§

impl<S, M> Send for ClientBuilder<S, M>where M: Send, S: Send,

§

impl<S, M> Sync for ClientBuilder<S, M>where M: Sync, S: Sync,

§

impl<S, M> Unpin for ClientBuilder<S, M>where M: Unpin, S: Unpin,

§

impl<S = (), M = ()> !UnwindSafe for ClientBuilder<S, M>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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 Twhere U: From<T>,

const: unstable · 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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

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