mirror of
https://github.com/actix/actix-web.git
synced 2024-11-22 17:41:11 +00:00
allow to use custom resolver for ClientConnector
This commit is contained in:
parent
4fe2f6b763
commit
9151d61eda
2 changed files with 17 additions and 4 deletions
|
@ -28,7 +28,7 @@
|
|||
* Remove `Route::with2()` and `Route::with3()` use tuple of extractors instead.
|
||||
|
||||
|
||||
## [0.6.12] - 2018-06-07
|
||||
## [0.6.12] - 2018-06-08
|
||||
|
||||
### Added
|
||||
|
||||
|
@ -38,6 +38,8 @@
|
|||
|
||||
* Improved failure interoperability with downcasting #285
|
||||
|
||||
* Allow to use custom resolver for `ClientConnector`
|
||||
|
||||
|
||||
## [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::{
|
||||
fut, Actor, ActorFuture, ActorResponse, AsyncContext, Context, ContextFutureSpawner,
|
||||
Handler, Message, Recipient, StreamHandler, Supervised, SystemService, WrapFuture,
|
||||
fut, Actor, ActorFuture, ActorResponse, Addr, AsyncContext, Context,
|
||||
ContextFutureSpawner, Handler, Message, Recipient, StreamHandler, Supervised,
|
||||
SystemService, WrapFuture,
|
||||
};
|
||||
|
||||
use futures::sync::{mpsc, oneshot};
|
||||
|
@ -197,6 +198,7 @@ pub struct ClientConnector {
|
|||
acq_tx: mpsc::UnboundedSender<AcquiredConnOperation>,
|
||||
acq_rx: Option<mpsc::UnboundedReceiver<AcquiredConnOperation>>,
|
||||
|
||||
resolver: Addr<Connector>,
|
||||
conn_lifetime: Duration,
|
||||
conn_keep_alive: Duration,
|
||||
limit: usize,
|
||||
|
@ -240,6 +242,7 @@ impl Default for ClientConnector {
|
|||
subscriber: None,
|
||||
acq_tx: tx,
|
||||
acq_rx: Some(rx),
|
||||
resolver: Connector::from_registry(),
|
||||
connector: builder.build().unwrap(),
|
||||
conn_lifetime: Duration::from_secs(75),
|
||||
conn_keep_alive: Duration::from_secs(15),
|
||||
|
@ -263,6 +266,7 @@ impl Default for ClientConnector {
|
|||
subscriber: None,
|
||||
acq_tx: tx,
|
||||
acq_rx: Some(rx),
|
||||
resolver: Connector::from_registry(),
|
||||
conn_lifetime: Duration::from_secs(75),
|
||||
conn_keep_alive: Duration::from_secs(15),
|
||||
limit: 100,
|
||||
|
@ -329,6 +333,7 @@ impl ClientConnector {
|
|||
subscriber: None,
|
||||
acq_tx: tx,
|
||||
acq_rx: Some(rx),
|
||||
resolver: Connector::from_registry(),
|
||||
conn_lifetime: Duration::from_secs(75),
|
||||
conn_keep_alive: Duration::from_secs(15),
|
||||
limit: 100,
|
||||
|
@ -388,6 +393,12 @@ impl ClientConnector {
|
|||
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 {
|
||||
// check limits
|
||||
if self.limit > 0 {
|
||||
|
@ -655,7 +666,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