1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 14:49:20 +02:00

rename client io trait. reduce duplicate code (#2079)

This commit is contained in:
fakeshadow
2021-03-16 09:31:14 -07:00
committed by GitHub
parent 69dd1a9bd6
commit c8f6d37290
4 changed files with 26 additions and 75 deletions

View File

@ -19,6 +19,10 @@ use super::error::SendRequestError;
use super::pool::Acquired;
use super::{h1proto, h2proto};
pub trait ConnectionIo: AsyncRead + AsyncWrite + Unpin + 'static {}
impl<T: AsyncRead + AsyncWrite + Unpin + 'static> ConnectionIo for T {}
pub(crate) enum ConnectionType<Io> {
H1(Io),
H2(H2Connection),

View File

@ -18,7 +18,7 @@ use futures_core::ready;
use http::Uri;
use super::config::ConnectorConfig;
use super::connection::{Connection, EitherIoConnection};
use super::connection::{Connection, ConnectionIo, EitherIoConnection};
use super::error::ConnectError;
use super::pool::ConnectionPool;
use super::Connect;
@ -61,9 +61,6 @@ pub struct Connector<T> {
ssl: SslConnector,
}
pub trait Io: AsyncRead + AsyncWrite + Unpin {}
impl<T: AsyncRead + AsyncWrite + Unpin> Io for T {}
impl Connector<()> {
#[allow(clippy::new_ret_no_self, clippy::let_unit_value)]
pub fn new() -> Connector<
@ -281,16 +278,16 @@ where
pub type DummyService = Box<
dyn Service<
Connect,
Response = (Box<dyn Io>, Protocol),
Response = (Box<dyn ConnectionIo>, Protocol),
Error = ConnectError,
Future = futures_core::future::LocalBoxFuture<
'static,
Result<(Box<dyn Io>, Protocol), ConnectError>,
Result<(Box<dyn ConnectionIo>, Protocol), ConnectError>,
>,
>,
>;
InnerConnector::<_, DummyService, _, Box<dyn Io>> {
InnerConnector::<_, DummyService, _, Box<dyn ConnectionIo>> {
tcp_pool: ConnectionPool::new(
tcp_service,
self.config.no_disconnect_timeout(),
@ -334,9 +331,12 @@ where
.map(|protos| protos.windows(2).any(|w| w == H2))
.unwrap_or(false);
if h2 {
(Box::new(sock) as Box<dyn Io>, Protocol::Http2)
(
Box::new(sock) as Box<dyn ConnectionIo>,
Protocol::Http2,
)
} else {
(Box::new(sock) as Box<dyn Io>, Protocol::Http1)
(Box::new(sock) as _, Protocol::Http1)
}
})
.map_err(ConnectError::from),
@ -354,9 +354,9 @@ where
.map(|protos| protos.windows(2).any(|w| w == H2))
.unwrap_or(false);
if h2 {
(Box::new(sock) as Box<dyn Io>, Protocol::Http2)
(Box::new(sock) as _, Protocol::Http2)
} else {
(Box::new(sock) as Box<dyn Io>, Protocol::Http1)
(Box::new(sock) as _, Protocol::Http1)
}
}),
),

View File

@ -14,7 +14,7 @@ pub use actix_tls::connect::{
Connect as TcpConnect, ConnectError as TcpConnectError, Connection as TcpConnection,
};
pub use self::connection::Connection;
pub use self::connection::{Connection, ConnectionIo};
pub use self::connector::Connector;
pub use self::error::{ConnectError, FreezeRequestError, InvalidUrl, SendRequestError};
pub use crate::Protocol;