1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-24 08:22:59 +01:00

update Connector usage

This commit is contained in:
Nikolay Kim 2018-10-23 22:41:30 -07:00
parent bc6e62349c
commit cd0223e8b7

View File

@ -2,7 +2,7 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use actix_net::codec::Framed; use actix_net::codec::Framed;
use actix_net::connector::{ConnectorError, DefaultConnector}; use actix_net::connector::{Connect as TcpConnect, ConnectorError, DefaultConnector};
use actix_net::service::Service; use actix_net::service::Service;
use base64; use base64;
use futures::future::{err, Either, FutureResult}; use futures::future::{err, Either, FutureResult};
@ -20,7 +20,7 @@ use ws::Codec;
use super::{ClientError, Connect, Protocol}; use super::{ClientError, Connect, Protocol};
/// Default client, uses default connector. /// Default client, uses default connector.
pub type DefaultClient = Client<DefaultConnector<String>>; pub type DefaultClient = Client<DefaultConnector>;
/// WebSocket's client /// WebSocket's client
pub struct Client<T> pub struct Client<T>
@ -33,7 +33,7 @@ where
impl<T> Client<T> impl<T> Client<T>
where where
T: Service<Request = String, Error = ConnectorError>, T: Service<Request = TcpConnect, Error = ConnectorError>,
T::Response: AsyncRead + AsyncWrite, T::Response: AsyncRead + AsyncWrite,
{ {
/// Create new websocket's client factory /// Create new websocket's client factory
@ -42,7 +42,7 @@ where
} }
} }
impl Default for Client<DefaultConnector<String>> { impl Default for Client<DefaultConnector> {
fn default() -> Self { fn default() -> Self {
Client::new(DefaultConnector::default()) Client::new(DefaultConnector::default())
} }
@ -50,7 +50,7 @@ impl Default for Client<DefaultConnector<String>> {
impl<T> Clone for Client<T> impl<T> Clone for Client<T>
where where
T: Service<Request = String, Error = ConnectorError> + Clone, T: Service<Request = TcpConnect, Error = ConnectorError> + Clone,
T::Response: AsyncRead + AsyncWrite, T::Response: AsyncRead + AsyncWrite,
{ {
fn clone(&self) -> Self { fn clone(&self) -> Self {
@ -62,7 +62,7 @@ where
impl<T> Service for Client<T> impl<T> Service for Client<T>
where where
T: Service<Request = String, Error = ConnectorError>, T: Service<Request = TcpConnect, Error = ConnectorError>,
T::Response: AsyncRead + AsyncWrite + 'static, T::Response: AsyncRead + AsyncWrite + 'static,
T::Future: 'static, T::Future: 'static,
{ {
@ -129,18 +129,14 @@ where
); );
// prep connection // prep connection
let host = { let connect = TcpConnect::new(
let uri = request.uri(); request.uri().host().unwrap(),
format!( request.uri().port().unwrap_or_else(|| proto.port()),
"{}:{}", );
uri.host().unwrap(),
uri.port().unwrap_or_else(|| proto.port())
)
};
let fut = Box::new( let fut = Box::new(
self.connector self.connector
.call(host) .call(connect)
.map_err(|e| ClientError::from(e)) .map_err(|e| ClientError::from(e))
.and_then(move |io| { .and_then(move |io| {
// h1 protocol // h1 protocol