1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-31 08:57:00 +02:00

refactor actix_http connection types and connector services (#2081)

This commit is contained in:
fakeshadow
2021-03-18 10:53:22 -07:00
committed by GitHub
parent abcb444dd9
commit b75b5114c3
16 changed files with 867 additions and 611 deletions

View File

@@ -2,6 +2,7 @@ use std::{
future::Future,
net,
pin::Pin,
rc::Rc,
task::{Context, Poll},
};
@@ -19,7 +20,7 @@ use futures_core::{future::LocalBoxFuture, ready};
use crate::response::ClientResponse;
pub type ConnectorService = Box<
pub type BoxConnectorService = Rc<
dyn Service<
ConnectRequest,
Response = ConnectResponse,
@@ -28,6 +29,8 @@ pub type ConnectorService = Box<
>,
>;
pub type BoxedSocket = Box<dyn ConnectionIo>;
pub enum ConnectRequest {
Client(RequestHeadType, Body, Option<net::SocketAddr>),
Tunnel(RequestHead, Option<net::SocketAddr>),
@@ -58,7 +61,7 @@ impl ConnectResponse {
}
}
pub(crate) struct DefaultConnector<S> {
pub struct DefaultConnector<S> {
connector: S,
}
@@ -68,15 +71,14 @@ impl<S> DefaultConnector<S> {
}
}
impl<S> Service<ConnectRequest> for DefaultConnector<S>
impl<S, Io> Service<ConnectRequest> for DefaultConnector<S>
where
S: Service<ClientConnect, Error = ConnectError>,
S::Response: Connection,
<S::Response as Connection>::Io: 'static,
S: Service<ClientConnect, Error = ConnectError, Response = Connection<Io>>,
Io: ConnectionIo,
{
type Response = ConnectResponse;
type Error = SendRequestError;
type Future = ConnectRequestFuture<S::Future, <S::Response as Connection>::Io>;
type Future = ConnectRequestFuture<S::Future, Io>;
actix_service::forward_ready!(connector);
@@ -102,7 +104,10 @@ where
pin_project_lite::pin_project! {
#[project = ConnectRequestProj]
pub(crate) enum ConnectRequestFuture<Fut, Io> {
pub enum ConnectRequestFuture<Fut, Io>
where
Io: ConnectionIo
{
Connection {
#[pin]
fut: Fut,
@@ -114,16 +119,15 @@ pin_project_lite::pin_project! {
Tunnel {
fut: LocalBoxFuture<
'static,
Result<(ResponseHead, Framed<Io, ClientCodec>), SendRequestError>,
Result<(ResponseHead, Framed<Connection<Io>, ClientCodec>), SendRequestError>,
>,
}
}
}
impl<Fut, C, Io> Future for ConnectRequestFuture<Fut, Io>
impl<Fut, Io> Future for ConnectRequestFuture<Fut, Io>
where
Fut: Future<Output = Result<C, ConnectError>>,
C: Connection<Io = Io>,
Fut: Future<Output = Result<Connection<Io>, ConnectError>>,
Io: ConnectionIo,
{
type Output = Result<ConnectResponse, SendRequestError>;
@@ -165,5 +169,3 @@ where
}
}
}
pub type BoxedSocket = Box<dyn ConnectionIo>;