Struct actix_web::client::ClientConnector
source · pub struct ClientConnector { /* private fields */ }
Expand description
ClientConnector
type is responsible for transport layer of a
client connection.
Implementations
sourceimpl ClientConnector
impl ClientConnector
sourcepub fn with_connector(connector: SslConnector) -> ClientConnector
pub fn with_connector(connector: SslConnector) -> ClientConnector
Create ClientConnector
actor with custom SslConnector
instance.
By default ClientConnector
uses very a simple SSL configuration.
With with_connector
method it is possible to use a custom
SslConnector
object.
extern crate openssl;
use actix_web::{actix, client::ClientConnector, client::Connect};
use openssl::ssl::{SslConnector, SslMethod};
fn main() {
actix::run(|| {
// Start `ClientConnector` with custom `SslConnector`
let ssl_conn = SslConnector::builder(SslMethod::tls()).unwrap().build();
let conn = ClientConnector::with_connector(ssl_conn).start();
conn.send(
Connect::new("https://www.rust-lang.org").unwrap()) // <- connect to host
.map_err(|_| ())
.and_then(|res| {
if let Ok(mut stream) = res {
stream.write_all(b"GET / HTTP/1.0\r\n\r\n").unwrap();
}
Ok(())
})
});
}
sourcepub fn limit(self, limit: usize) -> Self
pub fn limit(self, limit: usize) -> Self
Set total number of simultaneous connections.
If limit is 0, the connector has no limit. The default limit size is 100.
sourcepub fn limit_per_host(self, limit: usize) -> Self
pub fn limit_per_host(self, limit: usize) -> Self
Set total number of simultaneous connections to the same endpoint.
Endpoints are the same if they have equal (host, port, ssl) triplets. If limit is 0, the connector has no limit. The default limit size is 0.
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 stats(self, subs: Recipient<ClientConnectorStats>) -> Self
pub fn stats(self, subs: Recipient<ClientConnectorStats>) -> Self
Subscribe for connector stats. Only one subscriber is supported.
sourcepub fn resolver<A: Into<Recipient<ResolveConnect>>>(self, addr: A) -> Self
pub fn resolver<A: Into<Recipient<ResolveConnect>>>(self, addr: A) -> Self
Use custom resolver actor
By default actix’s Resolver is used.
Trait Implementations
sourceimpl Actor for ClientConnector
impl Actor for ClientConnector
type Context = Context<ClientConnector>
type Context = Context<ClientConnector>
sourcefn started(&mut self, ctx: &mut Self::Context)
fn started(&mut self, ctx: &mut Self::Context)
sourcefn stopping(&mut self, ctx: &mut Self::Context) -> Running
fn stopping(&mut self, ctx: &mut Self::Context) -> Running
Actor::Stopping
state. There
could be several reasons for stopping. Context::stop
get called
by the actor itself. All addresses to current actor get dropped and
no more evented objects left in the context. Read more