mirror of
https://github.com/actix/actix-web.git
synced 2024-12-18 14:16:47 +00:00
Allow to use custom resolver for ClientConnector
This commit is contained in:
parent
5eaf4cbefd
commit
4797298706
4 changed files with 20 additions and 8 deletions
|
@ -10,6 +10,8 @@
|
|||
|
||||
* Improved failure interoperability with downcasting #285
|
||||
|
||||
* Allow to use custom resolver for `ClientConnector`
|
||||
|
||||
|
||||
### Deprecated
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ flate2-rust = ["flate2/rust_backend"]
|
|||
features = ["tls", "alpn", "session", "brotli", "flate2-c"]
|
||||
|
||||
[dependencies]
|
||||
actix = "^0.5.5"
|
||||
actix = "^0.5.8"
|
||||
|
||||
base64 = "0.9"
|
||||
bitflags = "1.0"
|
||||
|
|
|
@ -674,7 +674,7 @@ where
|
|||
/// struct State2;
|
||||
///
|
||||
/// fn main() {
|
||||
/// //#### # thread::spawn(|| {
|
||||
/// # thread::spawn(|| {
|
||||
/// server::new(|| {
|
||||
/// vec![
|
||||
/// App::with_state(State1)
|
||||
|
@ -689,7 +689,7 @@ where
|
|||
/// }).bind("127.0.0.1:8080")
|
||||
/// .unwrap()
|
||||
/// .run()
|
||||
/// //#### # });
|
||||
/// # });
|
||||
/// }
|
||||
/// ```
|
||||
pub fn boxed(mut self) -> Box<HttpHandler> {
|
||||
|
|
|
@ -9,8 +9,8 @@ use actix::actors::{Connect as ResolveConnect, Connector, ConnectorError};
|
|||
use actix::fut::WrapFuture;
|
||||
use actix::registry::ArbiterService;
|
||||
use actix::{
|
||||
fut, Actor, ActorFuture, ActorResponse, Arbiter, AsyncContext, Context,
|
||||
ContextFutureSpawner, Handler, Message, Recipient, Supervised, Syn,
|
||||
fut, Actor, ActorFuture, ActorResponse, Addr, Arbiter, AsyncContext, Context,
|
||||
ContextFutureSpawner, Handler, Message, Recipient, Supervised, Syn, Unsync,
|
||||
};
|
||||
|
||||
use futures::task::{current as current_task, Task};
|
||||
|
@ -181,6 +181,7 @@ pub struct ClientConnector {
|
|||
pool: Rc<Pool>,
|
||||
pool_modified: Rc<Cell<bool>>,
|
||||
|
||||
resolver: Addr<Unsync, Connector>,
|
||||
conn_lifetime: Duration,
|
||||
conn_keep_alive: Duration,
|
||||
limit: usize,
|
||||
|
@ -225,6 +226,7 @@ impl Default for ClientConnector {
|
|||
pool: Rc::new(Pool::new(Rc::clone(&_modified))),
|
||||
pool_modified: _modified,
|
||||
connector: builder.build().unwrap(),
|
||||
resolver: Connector::from_registry(),
|
||||
conn_lifetime: Duration::from_secs(75),
|
||||
conn_keep_alive: Duration::from_secs(15),
|
||||
limit: 100,
|
||||
|
@ -245,6 +247,7 @@ impl Default for ClientConnector {
|
|||
subscriber: None,
|
||||
pool: Rc::new(Pool::new(Rc::clone(&_modified))),
|
||||
pool_modified: _modified,
|
||||
resolver: Connector::from_registry(),
|
||||
conn_lifetime: Duration::from_secs(75),
|
||||
conn_keep_alive: Duration::from_secs(15),
|
||||
limit: 100,
|
||||
|
@ -277,9 +280,9 @@ impl ClientConnector {
|
|||
/// # use std::io::Write;
|
||||
/// extern crate openssl;
|
||||
/// use actix::prelude::*;
|
||||
/// use actix_web::client::{Connect, ClientConnector};
|
||||
/// use actix_web::client::{ClientConnector, Connect};
|
||||
///
|
||||
/// use openssl::ssl::{SslMethod, SslConnector};
|
||||
/// use openssl::ssl::{SslConnector, SslMethod};
|
||||
///
|
||||
/// fn main() {
|
||||
/// let sys = System::new("test");
|
||||
|
@ -312,6 +315,7 @@ impl ClientConnector {
|
|||
subscriber: None,
|
||||
pool: Rc::new(Pool::new(Rc::clone(&modified))),
|
||||
pool_modified: modified,
|
||||
resolver: Connector::from_registry(),
|
||||
conn_lifetime: Duration::from_secs(75),
|
||||
conn_keep_alive: Duration::from_secs(15),
|
||||
limit: 100,
|
||||
|
@ -371,6 +375,12 @@ impl ClientConnector {
|
|||
self
|
||||
}
|
||||
|
||||
/// Use custom resolver actor
|
||||
pub fn resolver(mut self, addr: Addr<Unsync, Connector>) -> Self {
|
||||
self.resolver = addr;
|
||||
self
|
||||
}
|
||||
|
||||
fn acquire(&mut self, key: &Key) -> Acquire {
|
||||
// check limits
|
||||
if self.limit > 0 {
|
||||
|
@ -705,7 +715,7 @@ impl Handler<Connect> for ClientConnector {
|
|||
|
||||
{
|
||||
ActorResponse::async(
|
||||
Connector::from_registry()
|
||||
self.resolver
|
||||
.send(
|
||||
ResolveConnect::host_and_port(&conn.0.host, port)
|
||||
.timeout(conn_timeout),
|
||||
|
|
Loading…
Reference in a new issue