mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-23 16:21:06 +01:00
allow to use custom resolver for ClientConnector
This commit is contained in:
parent
4fe2f6b763
commit
9151d61eda
@ -28,7 +28,7 @@
|
|||||||
* Remove `Route::with2()` and `Route::with3()` use tuple of extractors instead.
|
* Remove `Route::with2()` and `Route::with3()` use tuple of extractors instead.
|
||||||
|
|
||||||
|
|
||||||
## [0.6.12] - 2018-06-07
|
## [0.6.12] - 2018-06-08
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
@ -38,6 +38,8 @@
|
|||||||
|
|
||||||
* Improved failure interoperability with downcasting #285
|
* Improved failure interoperability with downcasting #285
|
||||||
|
|
||||||
|
* Allow to use custom resolver for `ClientConnector`
|
||||||
|
|
||||||
|
|
||||||
## [0.6.11] - 2018-06-05
|
## [0.6.11] - 2018-06-05
|
||||||
|
|
||||||
|
@ -5,8 +5,9 @@ use std::{fmt, io, mem, time};
|
|||||||
|
|
||||||
use actix::resolver::{Connect as ResolveConnect, Connector, ConnectorError};
|
use actix::resolver::{Connect as ResolveConnect, Connector, ConnectorError};
|
||||||
use actix::{
|
use actix::{
|
||||||
fut, Actor, ActorFuture, ActorResponse, AsyncContext, Context, ContextFutureSpawner,
|
fut, Actor, ActorFuture, ActorResponse, Addr, AsyncContext, Context,
|
||||||
Handler, Message, Recipient, StreamHandler, Supervised, SystemService, WrapFuture,
|
ContextFutureSpawner, Handler, Message, Recipient, StreamHandler, Supervised,
|
||||||
|
SystemService, WrapFuture,
|
||||||
};
|
};
|
||||||
|
|
||||||
use futures::sync::{mpsc, oneshot};
|
use futures::sync::{mpsc, oneshot};
|
||||||
@ -197,6 +198,7 @@ pub struct ClientConnector {
|
|||||||
acq_tx: mpsc::UnboundedSender<AcquiredConnOperation>,
|
acq_tx: mpsc::UnboundedSender<AcquiredConnOperation>,
|
||||||
acq_rx: Option<mpsc::UnboundedReceiver<AcquiredConnOperation>>,
|
acq_rx: Option<mpsc::UnboundedReceiver<AcquiredConnOperation>>,
|
||||||
|
|
||||||
|
resolver: Addr<Connector>,
|
||||||
conn_lifetime: Duration,
|
conn_lifetime: Duration,
|
||||||
conn_keep_alive: Duration,
|
conn_keep_alive: Duration,
|
||||||
limit: usize,
|
limit: usize,
|
||||||
@ -240,6 +242,7 @@ impl Default for ClientConnector {
|
|||||||
subscriber: None,
|
subscriber: None,
|
||||||
acq_tx: tx,
|
acq_tx: tx,
|
||||||
acq_rx: Some(rx),
|
acq_rx: Some(rx),
|
||||||
|
resolver: Connector::from_registry(),
|
||||||
connector: builder.build().unwrap(),
|
connector: builder.build().unwrap(),
|
||||||
conn_lifetime: Duration::from_secs(75),
|
conn_lifetime: Duration::from_secs(75),
|
||||||
conn_keep_alive: Duration::from_secs(15),
|
conn_keep_alive: Duration::from_secs(15),
|
||||||
@ -263,6 +266,7 @@ impl Default for ClientConnector {
|
|||||||
subscriber: None,
|
subscriber: None,
|
||||||
acq_tx: tx,
|
acq_tx: tx,
|
||||||
acq_rx: Some(rx),
|
acq_rx: Some(rx),
|
||||||
|
resolver: Connector::from_registry(),
|
||||||
conn_lifetime: Duration::from_secs(75),
|
conn_lifetime: Duration::from_secs(75),
|
||||||
conn_keep_alive: Duration::from_secs(15),
|
conn_keep_alive: Duration::from_secs(15),
|
||||||
limit: 100,
|
limit: 100,
|
||||||
@ -329,6 +333,7 @@ impl ClientConnector {
|
|||||||
subscriber: None,
|
subscriber: None,
|
||||||
acq_tx: tx,
|
acq_tx: tx,
|
||||||
acq_rx: Some(rx),
|
acq_rx: Some(rx),
|
||||||
|
resolver: Connector::from_registry(),
|
||||||
conn_lifetime: Duration::from_secs(75),
|
conn_lifetime: Duration::from_secs(75),
|
||||||
conn_keep_alive: Duration::from_secs(15),
|
conn_keep_alive: Duration::from_secs(15),
|
||||||
limit: 100,
|
limit: 100,
|
||||||
@ -388,6 +393,12 @@ impl ClientConnector {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Use custom resolver actor
|
||||||
|
pub fn resolver(mut self, addr: Addr<Connector>) -> Self {
|
||||||
|
self.resolver = addr;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
fn acquire(&mut self, key: &Key) -> Acquire {
|
fn acquire(&mut self, key: &Key) -> Acquire {
|
||||||
// check limits
|
// check limits
|
||||||
if self.limit > 0 {
|
if self.limit > 0 {
|
||||||
@ -655,7 +666,7 @@ impl Handler<Connect> for ClientConnector {
|
|||||||
|
|
||||||
{
|
{
|
||||||
ActorResponse::async(
|
ActorResponse::async(
|
||||||
Connector::from_registry()
|
self.resolver
|
||||||
.send(
|
.send(
|
||||||
ResolveConnect::host_and_port(&conn.0.host, port)
|
ResolveConnect::host_and_port(&conn.0.host, port)
|
||||||
.timeout(conn_timeout),
|
.timeout(conn_timeout),
|
||||||
|
Loading…
Reference in New Issue
Block a user