pub struct Connector<T> { /* private fields */ }Expand description
Manages HTTP client network connectivity.
The Connector type uses a builder-like combinator pattern for service construction that
finishes by calling the .finish() method.
use std::time::Duration;
let connector = awc::Connector::new()
.timeout(Duration::from_secs(5))
.finish();Implementations§
Source§impl Connector<()>
impl Connector<()>
Sourcepub fn new() -> Connector<impl Service<ConnectInfo<Uri>, Response = TcpConnection<Uri, TcpStream>, Error = ConnectError> + Clone>
pub fn new() -> Connector<impl Service<ConnectInfo<Uri>, Response = TcpConnection<Uri, TcpStream>, Error = ConnectError> + Clone>
Create a new connector with default TLS settings
§Panics
- When the
rustls-0_23-webpki-rootsorrustls-0_23-native-rootsfeatures are enabled and no default crypto provider has been loaded, this method will panic. - When the
rustls-0_23-native-rootsorrustls-0_22-native-rootsfeatures are enabled and the runtime system has no native root certificates, this method will panic.
Source§impl<S> Connector<S>
impl<S> Connector<S>
Sourcepub fn connector<S1, Io1>(self, connector: S1) -> Connector<S1>where
Io1: ActixStream + Debug + 'static,
S1: Service<ConnectInfo<Uri>, Response = TcpConnection<Uri, Io1>, Error = TcpConnectError> + Clone,
pub fn connector<S1, Io1>(self, connector: S1) -> Connector<S1>where
Io1: ActixStream + Debug + 'static,
S1: Service<ConnectInfo<Uri>, Response = TcpConnection<Uri, Io1>, Error = TcpConnectError> + Clone,
Sets custom connector.
Source§impl<S, IO> Connector<S>where
IO: ActixStream + Debug + 'static,
S: Service<ConnectInfo<Uri>, Response = Connection<Uri, IO>, Error = ConnectError> + Clone + 'static,
impl<S, IO> Connector<S>where
IO: ActixStream + Debug + 'static,
S: Service<ConnectInfo<Uri>, Response = Connection<Uri, IO>, Error = ConnectError> + Clone + 'static,
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Sets TCP connection timeout.
This is the max time allowed to connect to remote host, including DNS name resolution.
By default, the timeout is 5 seconds.
Sourcepub fn handshake_timeout(self, timeout: Duration) -> Self
pub fn handshake_timeout(self, timeout: Duration) -> Self
Sets TLS handshake timeout.
This is the max time allowed to perform the TLS handshake with remote host after TCP connection is established.
By default, the timeout is 5 seconds.
Sourcepub fn rustls_0_23(self, connector: Arc<ClientConfig>) -> Self
pub fn rustls_0_23(self, connector: Arc<ClientConfig>) -> Self
Sets custom Rustls v0.23 ClientConfig instance.
In order to enable ALPN, set the .alpn_protocols field on the ClientConfig to the
following:
vec![b"h2".to_vec(), b"http/1.1".to_vec()]Sourcepub fn max_http_version(self, val: Version) -> Self
pub fn max_http_version(self, val: Version) -> Self
Sets maximum supported HTTP major version.
Supported versions are HTTP/1.1 and HTTP/2.
Sourcepub fn initial_window_size(self, size: u32) -> Self
pub fn initial_window_size(self, size: u32) -> Self
Sets the initial window size (in bytes) for HTTP/2 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
Sets the initial window size (in bytes) for HTTP/2 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 limit(self, limit: usize) -> Self
pub fn limit(self, limit: usize) -> Self
Set total number of simultaneous connections per type of scheme.
If limit is 0, the connector has no limit.
The default limit size is 100.
Sourcepub fn conn_keep_alive(self, dur: Duration) -> Self
pub fn conn_keep_alive(self, dur: Duration) -> Self
Set keep-alive period for opened connection.
Keep-alive period is the period between connection usage. If the delay between repeated usages of the same connection exceeds this period, the connection is closed. Default keep-alive period is 15 seconds.
Sourcepub fn conn_lifetime(self, dur: Duration) -> Self
pub fn conn_lifetime(self, dur: Duration) -> Self
Set max lifetime period for connection.
Connection lifetime is max lifetime of any opened connection until it is closed regardless of keep-alive period. Default lifetime period is 75 seconds.
Sourcepub fn disconnect_timeout(self, dur: Duration) -> Self
pub fn disconnect_timeout(self, dur: Duration) -> Self
Set server connection disconnect timeout in milliseconds.
Defines a timeout for disconnect connection. If a disconnect procedure does not complete within this time, the socket get dropped. This timeout affects only secure connections.
To disable timeout set value to 0.
By default disconnect timeout is set to 3000 milliseconds.
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 finish(
self,
) -> 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>>
pub fn finish( self, ) -> 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>>
Finish configuration process and create connector service.
The Connector builder always concludes by calling finish() last in its combinator chain.