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

update client connector

This commit is contained in:
Nikolay Kim 2019-03-13 22:57:28 -07:00
parent 3a24a75d13
commit d2c755bb47
3 changed files with 13 additions and 14 deletions

View File

@ -61,8 +61,8 @@ impl Address for Connect {
&self.uri.host().unwrap()
}
fn port(&self) -> u16 {
if let Some(port) = self.uri.port() {
fn port(&self) -> Option<u16> {
let port = if let Some(port) = self.uri.port() {
port
} else if let Some(scheme) = self.uri.scheme_part() {
match scheme.as_str() {
@ -72,6 +72,7 @@ impl Address for Connect {
}
} else {
80
}
};
Some(port)
}
}

View File

@ -173,7 +173,7 @@ where
let connector = TimeoutService::new(
self.timeout,
apply_fn(self.connector, |msg: Connect, srv| {
srv.call(actix_connect::Connect::with(msg))
srv.call(actix_connect::Connect::new(msg))
})
.map(|stream| (stream.into_parts().0, Protocol::Http1)),
)
@ -200,7 +200,7 @@ where
let ssl_service = TimeoutService::new(
self.timeout,
apply_fn(self.connector.clone(), |msg: Connect, srv| {
srv.call(actix_connect::Connect::with(msg))
srv.call(actix_connect::Connect::new(msg))
})
.map_err(ConnectError::from)
.and_then(
@ -230,7 +230,7 @@ where
let tcp_service = TimeoutService::new(
self.timeout,
apply_fn(self.connector.clone(), |msg: Connect, srv| {
srv.call(actix_connect::Connect::with(msg))
srv.call(actix_connect::Connect::new(msg))
})
.map_err(ConnectError::from)
.map(|stream| (stream.into_parts().0, Protocol::Http1)),

View File

@ -29,7 +29,7 @@ impl Client<()> {
/// Create client with default connector.
pub fn default() -> Client<
impl Service<
Request = TcpConnect<(String, u16)>,
Request = TcpConnect<String>,
Response = impl AsyncRead + AsyncWrite,
Error = ConnectError,
> + Clone,
@ -42,7 +42,7 @@ impl Client<()> {
impl<T> Client<T>
where
T: Service<Request = TcpConnect<(String, u16)>, Error = ConnectError>,
T: Service<Request = TcpConnect<String>, Error = ConnectError>,
T::Response: AsyncRead + AsyncWrite,
{
/// Create new websocket's client factory
@ -53,7 +53,7 @@ where
impl<T> Clone for Client<T>
where
T: Service<Request = TcpConnect<(String, u16)>, Error = ConnectError> + Clone,
T: Service<Request = TcpConnect<String>, Error = ConnectError> + Clone,
T::Response: AsyncRead + AsyncWrite,
{
fn clone(&self) -> Self {
@ -65,7 +65,7 @@ where
impl<T> Service for Client<T>
where
T: Service<Request = TcpConnect<(String, u16)>, Error = ConnectError>,
T: Service<Request = TcpConnect<String>, Error = ConnectError>,
T::Response: AsyncRead + AsyncWrite + 'static,
T::Future: 'static,
{
@ -130,10 +130,8 @@ where
);
// prep connection
let connect = TcpConnect::from_string(
request.uri().host().unwrap().to_string(),
request.uri().port().unwrap_or_else(|| proto.port()),
);
let connect = TcpConnect::new(request.uri().host().unwrap().to_string())
.set_port(request.uri().port().unwrap_or_else(|| proto.port()));
let fut = Box::new(
self.connector