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
impl ClientBuilder
sourcepub fn new(
) -> ClientBuilder<impl Service<ConnectInfo<Uri>, Response = TcpConnection<Uri, TcpStream>, Error = TcpConnectError> + Clone, ()>
pub fn new( ) -> ClientBuilder<impl Service<ConnectInfo<Uri>, Response = TcpConnection<Uri, TcpStream>, Error = TcpConnectError> + Clone, ()>
Create a new ClientBuilder with default settings
Note: If the rustls-0_23
feature is enabled and neither rustls-0_23-native-roots
nor
rustls-0_23-webpki-roots
are enabled, this ClientBuilder will build without TLS. In order
to enable TLS in this scenario, a custom Connector
must be added to the builder before
finishing construction.
source§impl<S, Io, M> ClientBuilder<S, M>
impl<S, Io, M> ClientBuilder<S, M>
sourcepub fn connector<S1, Io1>(
self,
connector: Connector<S1>
) -> ClientBuilder<S1, M>
pub fn connector<S1, Io1>( self, connector: Connector<S1> ) -> ClientBuilder<S1, M>
Use custom connector service.
sourcepub fn timeout(self, timeout: Duration) -> Self
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.
sourcepub fn disable_timeout(self) -> Self
pub fn disable_timeout(self) -> Self
Disable request timeout.
sourcepub fn local_address(self, addr: IpAddr) -> Self
pub fn local_address(self, addr: IpAddr) -> Self
Set local IP Address the connector would use for establishing connection.
sourcepub fn max_http_version(self, val: Version) -> Self
pub fn max_http_version(self, val: Version) -> Self
Maximum supported HTTP major version.
Supported versions are HTTP/1.1 and HTTP/2.
sourcepub fn disable_redirects(self) -> Self
pub fn disable_redirects(self) -> Self
Do not follow redirects.
Redirects are allowed by default.
sourcepub fn max_redirects(self, num: u8) -> Self
pub fn max_redirects(self, num: u8) -> Self
Set max number of redirects.
Max redirects is set to 10 by default.
sourcepub fn initial_window_size(self, size: u32) -> Self
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.
sourcepub fn initial_connection_window_size(self, size: u32) -> Self
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.
sourcepub fn no_default_headers(self) -> Self
pub fn no_default_headers(self) -> Self
Do not add fundamental default request headers.
By default Date
and User-Agent
headers are set.
sourcepub fn add_default_header(self, header: impl TryIntoHeaderPair) -> Self
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.
sourcepub fn basic_auth<N>(self, username: N, password: Option<&str>) -> Selfwhere
N: Display,
pub fn basic_auth<N>(self, username: N, password: Option<&str>) -> Selfwhere
N: Display,
Set client wide HTTP basic authorization header
sourcepub fn bearer_auth<T>(self, token: T) -> Selfwhere
T: Display,
pub fn bearer_auth<T>(self, token: T) -> Selfwhere
T: Display,
Set client wide HTTP bearer authentication header
sourcepub fn wrap<S1, M1>(
self,
mw: M1
) -> ClientBuilder<S, NestTransform<M, M1, S1, ConnectRequest>>
pub fn wrap<S1, M1>( self, mw: M1 ) -> ClientBuilder<S, NestTransform<M, M1, S1, 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
.
sourcepub 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>,
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.