2021-06-17 17:57:58 +01:00
|
|
|
use std::{
|
|
|
|
fmt,
|
|
|
|
marker::PhantomData,
|
|
|
|
net,
|
|
|
|
rc::Rc,
|
|
|
|
task::{Context, Poll},
|
|
|
|
};
|
2018-10-04 20:02:10 -07:00
|
|
|
|
2019-12-02 17:33:11 +06:00
|
|
|
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
|
|
|
use actix_rt::net::TcpStream;
|
2021-04-16 20:28:21 +01:00
|
|
|
use actix_service::{
|
|
|
|
fn_service, IntoServiceFactory, Service, ServiceFactory, ServiceFactoryExt as _,
|
|
|
|
};
|
2021-04-01 15:26:13 +01:00
|
|
|
use actix_utils::future::ready;
|
2021-03-29 19:06:16 -07:00
|
|
|
use futures_core::future::LocalBoxFuture;
|
2018-10-04 20:02:10 -07:00
|
|
|
|
2021-06-17 17:57:58 +01:00
|
|
|
use crate::{
|
2021-12-04 19:40:47 +00:00
|
|
|
body::{BoxBody, MessageBody},
|
2021-06-17 17:57:58 +01:00
|
|
|
config::ServiceConfig,
|
|
|
|
error::DispatchError,
|
|
|
|
service::HttpServiceHandler,
|
|
|
|
ConnectCallback, OnConnectData, Request, Response,
|
|
|
|
};
|
2018-10-04 20:02:10 -07:00
|
|
|
|
2021-06-17 17:57:58 +01:00
|
|
|
use super::{codec::Codec, dispatcher::Dispatcher, ExpectHandler, UpgradeHandler};
|
2018-10-04 20:02:10 -07:00
|
|
|
|
2019-11-15 15:54:11 +06:00
|
|
|
/// `ServiceFactory` implementation for HTTP1 transport
|
2021-01-04 07:47:04 +08:00
|
|
|
pub struct H1Service<T, S, B, X = ExpectHandler, U = UpgradeHandler> {
|
2018-10-04 20:02:10 -07:00
|
|
|
srv: S,
|
|
|
|
cfg: ServiceConfig,
|
2019-04-05 16:46:44 -07:00
|
|
|
expect: X,
|
2019-04-08 14:51:16 -07:00
|
|
|
upgrade: Option<U>,
|
2020-10-30 02:03:26 +00:00
|
|
|
on_connect_ext: Option<Rc<ConnectCallback<T>>>,
|
2021-01-04 00:49:02 +00:00
|
|
|
_phantom: PhantomData<B>,
|
2018-10-04 20:02:10 -07:00
|
|
|
}
|
|
|
|
|
2019-12-02 17:33:11 +06:00
|
|
|
impl<T, S, B> H1Service<T, S, B>
|
2018-10-04 20:02:10 -07:00
|
|
|
where
|
2021-01-04 07:47:04 +08:00
|
|
|
S: ServiceFactory<Request, Config = ()>,
|
2021-12-04 19:40:47 +00:00
|
|
|
S::Error: Into<Response<BoxBody>>,
|
2019-04-05 16:46:44 -07:00
|
|
|
S::InitError: fmt::Debug,
|
2019-02-09 08:44:22 -08:00
|
|
|
S::Response: Into<Response<B>>,
|
2018-11-17 20:21:28 -08:00
|
|
|
B: MessageBody,
|
2018-10-04 20:02:10 -07:00
|
|
|
{
|
2019-03-04 15:58:39 -08:00
|
|
|
/// Create new `HttpService` instance with config.
|
2021-01-04 07:47:04 +08:00
|
|
|
pub(crate) fn with_config<F: IntoServiceFactory<S, Request>>(
|
2019-11-15 15:54:11 +06:00
|
|
|
cfg: ServiceConfig,
|
|
|
|
service: F,
|
|
|
|
) -> Self {
|
2019-03-04 15:58:39 -08:00
|
|
|
H1Service {
|
|
|
|
cfg,
|
2019-11-15 15:54:11 +06:00
|
|
|
srv: service.into_factory(),
|
2019-04-05 16:46:44 -07:00
|
|
|
expect: ExpectHandler,
|
2019-04-08 14:51:16 -07:00
|
|
|
upgrade: None,
|
2020-10-30 02:03:26 +00:00
|
|
|
on_connect_ext: None,
|
2021-01-04 00:49:02 +00:00
|
|
|
_phantom: PhantomData,
|
2018-10-04 20:02:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-02 17:33:11 +06:00
|
|
|
impl<S, B, X, U> H1Service<TcpStream, S, B, X, U>
|
2019-04-05 16:46:44 -07:00
|
|
|
where
|
2021-01-04 07:47:04 +08:00
|
|
|
S: ServiceFactory<Request, Config = ()>,
|
2021-03-26 09:15:04 -07:00
|
|
|
S::Future: 'static,
|
2021-12-04 19:40:47 +00:00
|
|
|
S::Error: Into<Response<BoxBody>>,
|
2019-12-02 17:33:11 +06:00
|
|
|
S::InitError: fmt::Debug,
|
|
|
|
S::Response: Into<Response<B>>,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2019-12-02 17:33:11 +06:00
|
|
|
B: MessageBody,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2021-01-04 07:47:04 +08:00
|
|
|
X: ServiceFactory<Request, Config = (), Response = Request>,
|
2021-03-26 09:15:04 -07:00
|
|
|
X::Future: 'static,
|
2021-12-04 19:40:47 +00:00
|
|
|
X::Error: Into<Response<BoxBody>>,
|
2019-12-02 17:33:11 +06:00
|
|
|
X::InitError: fmt::Debug,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2021-01-04 07:47:04 +08:00
|
|
|
U: ServiceFactory<(Request, Framed<TcpStream, Codec>), Config = (), Response = ()>,
|
2021-03-26 09:15:04 -07:00
|
|
|
U::Future: 'static,
|
2021-12-04 19:40:47 +00:00
|
|
|
U::Error: fmt::Display + Into<Response<BoxBody>>,
|
2019-12-02 17:33:11 +06:00
|
|
|
U::InitError: fmt::Debug,
|
|
|
|
{
|
|
|
|
/// Create simple tcp stream service
|
|
|
|
pub fn tcp(
|
|
|
|
self,
|
|
|
|
) -> impl ServiceFactory<
|
2021-01-04 07:47:04 +08:00
|
|
|
TcpStream,
|
2019-12-02 17:33:11 +06:00
|
|
|
Config = (),
|
|
|
|
Response = (),
|
|
|
|
Error = DispatchError,
|
|
|
|
InitError = (),
|
|
|
|
> {
|
2021-04-16 20:28:21 +01:00
|
|
|
fn_service(|io: TcpStream| {
|
2019-12-02 17:33:11 +06:00
|
|
|
let peer_addr = io.peer_addr().ok();
|
2020-12-26 20:46:36 +08:00
|
|
|
ready(Ok((io, peer_addr)))
|
2019-12-02 17:33:11 +06:00
|
|
|
})
|
|
|
|
.and_then(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "openssl")]
|
|
|
|
mod openssl {
|
|
|
|
use super::*;
|
|
|
|
|
2021-03-26 09:15:04 -07:00
|
|
|
use actix_tls::accept::{
|
2021-11-30 14:12:04 +00:00
|
|
|
openssl::{
|
|
|
|
reexports::{Error as SslError, SslAcceptor},
|
|
|
|
Acceptor, TlsStream,
|
|
|
|
},
|
2021-03-26 09:15:04 -07:00
|
|
|
TlsError,
|
|
|
|
};
|
2019-12-02 17:33:11 +06:00
|
|
|
|
2021-02-27 19:57:09 +00:00
|
|
|
impl<S, B, X, U> H1Service<TlsStream<TcpStream>, S, B, X, U>
|
2019-12-02 17:33:11 +06:00
|
|
|
where
|
2021-01-04 07:47:04 +08:00
|
|
|
S: ServiceFactory<Request, Config = ()>,
|
2021-03-26 09:15:04 -07:00
|
|
|
S::Future: 'static,
|
2021-12-04 19:40:47 +00:00
|
|
|
S::Error: Into<Response<BoxBody>>,
|
2019-12-02 17:33:11 +06:00
|
|
|
S::InitError: fmt::Debug,
|
|
|
|
S::Response: Into<Response<B>>,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2019-12-02 17:33:11 +06:00
|
|
|
B: MessageBody,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2021-01-04 07:47:04 +08:00
|
|
|
X: ServiceFactory<Request, Config = (), Response = Request>,
|
2021-03-26 09:15:04 -07:00
|
|
|
X::Future: 'static,
|
2021-12-04 19:40:47 +00:00
|
|
|
X::Error: Into<Response<BoxBody>>,
|
2019-12-02 17:33:11 +06:00
|
|
|
X::InitError: fmt::Debug,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2019-12-02 17:33:11 +06:00
|
|
|
U: ServiceFactory<
|
2021-02-27 19:57:09 +00:00
|
|
|
(Request, Framed<TlsStream<TcpStream>, Codec>),
|
2019-12-02 17:33:11 +06:00
|
|
|
Config = (),
|
|
|
|
Response = (),
|
|
|
|
>,
|
2021-03-26 09:15:04 -07:00
|
|
|
U::Future: 'static,
|
2021-12-04 19:40:47 +00:00
|
|
|
U::Error: fmt::Display + Into<Response<BoxBody>>,
|
2019-12-02 17:33:11 +06:00
|
|
|
U::InitError: fmt::Debug,
|
|
|
|
{
|
2021-11-22 15:37:23 +00:00
|
|
|
/// Create OpenSSL based service.
|
2019-12-02 17:33:11 +06:00
|
|
|
pub fn openssl(
|
|
|
|
self,
|
|
|
|
acceptor: SslAcceptor,
|
|
|
|
) -> impl ServiceFactory<
|
2021-01-04 07:47:04 +08:00
|
|
|
TcpStream,
|
2019-12-02 17:33:11 +06:00
|
|
|
Config = (),
|
|
|
|
Response = (),
|
2021-01-04 07:47:04 +08:00
|
|
|
Error = TlsError<SslError, DispatchError>,
|
2019-12-02 17:33:11 +06:00
|
|
|
InitError = (),
|
|
|
|
> {
|
2021-04-16 20:28:21 +01:00
|
|
|
Acceptor::new(acceptor)
|
2021-11-22 15:37:23 +00:00
|
|
|
.map_init_err(|_| {
|
|
|
|
unreachable!("TLS acceptor service factory does not error on init")
|
|
|
|
})
|
|
|
|
.map_err(TlsError::into_service_error)
|
|
|
|
.map(|io: TlsStream<TcpStream>| {
|
2021-04-16 20:28:21 +01:00
|
|
|
let peer_addr = io.get_ref().peer_addr().ok();
|
2021-11-22 15:37:23 +00:00
|
|
|
(io, peer_addr)
|
2021-04-16 20:28:21 +01:00
|
|
|
})
|
|
|
|
.and_then(self.map_err(TlsError::Service))
|
2019-12-02 17:33:11 +06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-05 23:35:43 +06:00
|
|
|
#[cfg(feature = "rustls")]
|
|
|
|
mod rustls {
|
2021-03-26 09:15:04 -07:00
|
|
|
|
|
|
|
use std::io;
|
|
|
|
|
2021-11-22 15:37:23 +00:00
|
|
|
use actix_service::ServiceFactoryExt as _;
|
2021-03-26 09:15:04 -07:00
|
|
|
use actix_tls::accept::{
|
2021-11-30 14:12:04 +00:00
|
|
|
rustls::{reexports::ServerConfig, Acceptor, TlsStream},
|
2021-03-26 09:15:04 -07:00
|
|
|
TlsError,
|
|
|
|
};
|
2019-12-05 23:35:43 +06:00
|
|
|
|
2021-11-22 15:37:23 +00:00
|
|
|
use super::*;
|
|
|
|
|
2019-12-05 23:35:43 +06:00
|
|
|
impl<S, B, X, U> H1Service<TlsStream<TcpStream>, S, B, X, U>
|
|
|
|
where
|
2021-01-04 07:47:04 +08:00
|
|
|
S: ServiceFactory<Request, Config = ()>,
|
2021-03-26 09:15:04 -07:00
|
|
|
S::Future: 'static,
|
2021-12-04 19:40:47 +00:00
|
|
|
S::Error: Into<Response<BoxBody>>,
|
2019-12-05 23:35:43 +06:00
|
|
|
S::InitError: fmt::Debug,
|
|
|
|
S::Response: Into<Response<B>>,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2019-12-05 23:35:43 +06:00
|
|
|
B: MessageBody,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2021-01-04 07:47:04 +08:00
|
|
|
X: ServiceFactory<Request, Config = (), Response = Request>,
|
2021-03-26 09:15:04 -07:00
|
|
|
X::Future: 'static,
|
2021-12-04 19:40:47 +00:00
|
|
|
X::Error: Into<Response<BoxBody>>,
|
2019-12-05 23:35:43 +06:00
|
|
|
X::InitError: fmt::Debug,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2019-12-05 23:35:43 +06:00
|
|
|
U: ServiceFactory<
|
2021-01-04 07:47:04 +08:00
|
|
|
(Request, Framed<TlsStream<TcpStream>, Codec>),
|
2019-12-05 23:35:43 +06:00
|
|
|
Config = (),
|
|
|
|
Response = (),
|
|
|
|
>,
|
2021-03-26 09:15:04 -07:00
|
|
|
U::Future: 'static,
|
2021-12-04 19:40:47 +00:00
|
|
|
U::Error: fmt::Display + Into<Response<BoxBody>>,
|
2019-12-05 23:35:43 +06:00
|
|
|
U::InitError: fmt::Debug,
|
|
|
|
{
|
2021-11-22 15:37:23 +00:00
|
|
|
/// Create Rustls based service.
|
2019-12-05 23:35:43 +06:00
|
|
|
pub fn rustls(
|
|
|
|
self,
|
|
|
|
config: ServerConfig,
|
|
|
|
) -> impl ServiceFactory<
|
2021-01-04 07:47:04 +08:00
|
|
|
TcpStream,
|
2019-12-05 23:35:43 +06:00
|
|
|
Config = (),
|
|
|
|
Response = (),
|
2020-09-09 09:20:54 +01:00
|
|
|
Error = TlsError<io::Error, DispatchError>,
|
2019-12-05 23:35:43 +06:00
|
|
|
InitError = (),
|
|
|
|
> {
|
2021-04-16 20:28:21 +01:00
|
|
|
Acceptor::new(config)
|
2021-11-22 15:37:23 +00:00
|
|
|
.map_init_err(|_| {
|
|
|
|
unreachable!("TLS acceptor service factory does not error on init")
|
|
|
|
})
|
|
|
|
.map_err(TlsError::into_service_error)
|
|
|
|
.map(|io: TlsStream<TcpStream>| {
|
2021-04-16 20:28:21 +01:00
|
|
|
let peer_addr = io.get_ref().0.peer_addr().ok();
|
2021-11-22 15:37:23 +00:00
|
|
|
(io, peer_addr)
|
2021-04-16 20:28:21 +01:00
|
|
|
})
|
|
|
|
.and_then(self.map_err(TlsError::Service))
|
2019-12-05 23:35:43 +06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-02 17:33:11 +06:00
|
|
|
impl<T, S, B, X, U> H1Service<T, S, B, X, U>
|
|
|
|
where
|
2021-01-04 07:47:04 +08:00
|
|
|
S: ServiceFactory<Request, Config = ()>,
|
2021-12-04 19:40:47 +00:00
|
|
|
S::Error: Into<Response<BoxBody>>,
|
2019-04-05 16:46:44 -07:00
|
|
|
S::Response: Into<Response<B>>,
|
|
|
|
S::InitError: fmt::Debug,
|
|
|
|
B: MessageBody,
|
|
|
|
{
|
2019-12-02 17:33:11 +06:00
|
|
|
pub fn expect<X1>(self, expect: X1) -> H1Service<T, S, B, X1, U>
|
2019-04-05 16:46:44 -07:00
|
|
|
where
|
2021-01-04 07:47:04 +08:00
|
|
|
X1: ServiceFactory<Request, Response = Request>,
|
2021-12-04 19:40:47 +00:00
|
|
|
X1::Error: Into<Response<BoxBody>>,
|
2019-04-08 14:51:16 -07:00
|
|
|
X1::InitError: fmt::Debug,
|
2019-04-05 16:46:44 -07:00
|
|
|
{
|
|
|
|
H1Service {
|
|
|
|
expect,
|
|
|
|
cfg: self.cfg,
|
|
|
|
srv: self.srv,
|
2019-04-08 14:51:16 -07:00
|
|
|
upgrade: self.upgrade,
|
2020-10-30 02:03:26 +00:00
|
|
|
on_connect_ext: self.on_connect_ext,
|
2021-01-04 00:49:02 +00:00
|
|
|
_phantom: PhantomData,
|
2019-04-08 14:51:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-02 17:33:11 +06:00
|
|
|
pub fn upgrade<U1>(self, upgrade: Option<U1>) -> H1Service<T, S, B, X, U1>
|
2019-04-08 14:51:16 -07:00
|
|
|
where
|
2021-01-04 07:47:04 +08:00
|
|
|
U1: ServiceFactory<(Request, Framed<T, Codec>), Response = ()>,
|
2019-04-08 14:51:16 -07:00
|
|
|
U1::Error: fmt::Display,
|
|
|
|
U1::InitError: fmt::Debug,
|
|
|
|
{
|
|
|
|
H1Service {
|
|
|
|
upgrade,
|
|
|
|
cfg: self.cfg,
|
|
|
|
srv: self.srv,
|
|
|
|
expect: self.expect,
|
2020-10-30 02:03:26 +00:00
|
|
|
on_connect_ext: self.on_connect_ext,
|
2021-01-04 00:49:02 +00:00
|
|
|
_phantom: PhantomData,
|
2019-04-05 16:46:44 -07:00
|
|
|
}
|
|
|
|
}
|
2019-06-28 14:34:26 +06:00
|
|
|
|
2020-10-30 02:03:26 +00:00
|
|
|
/// Set on connect callback.
|
|
|
|
pub(crate) fn on_connect_ext(mut self, f: Option<Rc<ConnectCallback<T>>>) -> Self {
|
|
|
|
self.on_connect_ext = f;
|
|
|
|
self
|
|
|
|
}
|
2019-04-05 16:46:44 -07:00
|
|
|
}
|
|
|
|
|
2021-12-08 06:01:11 +00:00
|
|
|
impl<T, S, B, X, U> ServiceFactory<(T, Option<net::SocketAddr>)> for H1Service<T, S, B, X, U>
|
2018-10-04 20:02:10 -07:00
|
|
|
where
|
2021-03-26 09:15:04 -07:00
|
|
|
T: AsyncRead + AsyncWrite + Unpin + 'static,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2021-01-04 07:47:04 +08:00
|
|
|
S: ServiceFactory<Request, Config = ()>,
|
2021-03-26 09:15:04 -07:00
|
|
|
S::Future: 'static,
|
2021-12-04 19:40:47 +00:00
|
|
|
S::Error: Into<Response<BoxBody>>,
|
2019-02-09 08:44:22 -08:00
|
|
|
S::Response: Into<Response<B>>,
|
2019-04-05 16:46:44 -07:00
|
|
|
S::InitError: fmt::Debug,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2018-11-17 20:21:28 -08:00
|
|
|
B: MessageBody,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2021-01-04 07:47:04 +08:00
|
|
|
X: ServiceFactory<Request, Config = (), Response = Request>,
|
2021-03-26 09:15:04 -07:00
|
|
|
X::Future: 'static,
|
2021-12-04 19:40:47 +00:00
|
|
|
X::Error: Into<Response<BoxBody>>,
|
2019-04-05 16:46:44 -07:00
|
|
|
X::InitError: fmt::Debug,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2021-01-04 07:47:04 +08:00
|
|
|
U: ServiceFactory<(Request, Framed<T, Codec>), Config = (), Response = ()>,
|
2021-03-26 09:15:04 -07:00
|
|
|
U::Future: 'static,
|
2021-12-04 19:40:47 +00:00
|
|
|
U::Error: fmt::Display + Into<Response<BoxBody>>,
|
2019-04-08 14:51:16 -07:00
|
|
|
U::InitError: fmt::Debug,
|
2018-10-04 20:02:10 -07:00
|
|
|
{
|
2019-03-06 22:56:34 -08:00
|
|
|
type Response = ();
|
|
|
|
type Error = DispatchError;
|
2021-01-04 07:47:04 +08:00
|
|
|
type Config = ();
|
2019-12-02 17:33:11 +06:00
|
|
|
type Service = H1ServiceHandler<T, S::Service, B, X::Service, U::Service>;
|
2021-01-04 07:47:04 +08:00
|
|
|
type InitError = ();
|
2021-03-26 09:15:04 -07:00
|
|
|
type Future = LocalBoxFuture<'static, Result<Self::Service, Self::InitError>>;
|
2018-10-04 20:02:10 -07:00
|
|
|
|
2019-12-02 21:37:13 +06:00
|
|
|
fn new_service(&self, _: ()) -> Self::Future {
|
2021-03-26 09:15:04 -07:00
|
|
|
let service = self.srv.new_service(());
|
|
|
|
let expect = self.expect.new_service(());
|
|
|
|
let upgrade = self.upgrade.as_ref().map(|s| s.new_service(()));
|
|
|
|
let on_connect_ext = self.on_connect_ext.clone();
|
|
|
|
let cfg = self.cfg.clone();
|
|
|
|
|
|
|
|
Box::pin(async move {
|
|
|
|
let expect = expect
|
|
|
|
.await
|
|
|
|
.map_err(|e| log::error!("Init http expect service error: {:?}", e))?;
|
|
|
|
|
|
|
|
let upgrade = match upgrade {
|
|
|
|
Some(upgrade) => {
|
2021-12-08 06:01:11 +00:00
|
|
|
let upgrade = upgrade
|
|
|
|
.await
|
|
|
|
.map_err(|e| log::error!("Init http upgrade service error: {:?}", e))?;
|
2021-03-26 09:15:04 -07:00
|
|
|
Some(upgrade)
|
|
|
|
}
|
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
|
|
|
|
let service = service
|
|
|
|
.await
|
|
|
|
.map_err(|e| log::error!("Init http service error: {:?}", e))?;
|
|
|
|
|
|
|
|
Ok(H1ServiceHandler::new(
|
|
|
|
cfg,
|
2019-11-15 15:54:11 +06:00
|
|
|
service,
|
2021-03-26 09:15:04 -07:00
|
|
|
expect,
|
|
|
|
upgrade,
|
|
|
|
on_connect_ext,
|
|
|
|
))
|
|
|
|
})
|
2018-10-04 20:02:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-30 02:03:26 +00:00
|
|
|
/// `Service` implementation for HTTP/1 transport
|
2021-03-29 19:06:16 -07:00
|
|
|
pub type H1ServiceHandler<T, S, B, X, U> = HttpServiceHandler<T, S, B, X, U>;
|
2018-10-04 20:02:10 -07:00
|
|
|
|
2021-12-08 06:01:11 +00:00
|
|
|
impl<T, S, B, X, U> Service<(T, Option<net::SocketAddr>)> for HttpServiceHandler<T, S, B, X, U>
|
2018-10-04 20:02:10 -07:00
|
|
|
where
|
2019-12-02 17:33:11 +06:00
|
|
|
T: AsyncRead + AsyncWrite + Unpin,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2021-01-04 07:47:04 +08:00
|
|
|
S: Service<Request>,
|
2021-12-04 19:40:47 +00:00
|
|
|
S::Error: Into<Response<BoxBody>>,
|
2019-02-09 08:44:22 -08:00
|
|
|
S::Response: Into<Response<B>>,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2018-11-17 20:21:28 -08:00
|
|
|
B: MessageBody,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2021-01-04 07:47:04 +08:00
|
|
|
X: Service<Request, Response = Request>,
|
2021-12-04 19:40:47 +00:00
|
|
|
X::Error: Into<Response<BoxBody>>,
|
2021-05-05 18:36:02 +01:00
|
|
|
|
2021-01-04 07:47:04 +08:00
|
|
|
U: Service<(Request, Framed<T, Codec>), Response = ()>,
|
2021-12-04 19:40:47 +00:00
|
|
|
U::Error: fmt::Display + Into<Response<BoxBody>>,
|
2018-10-04 20:02:10 -07:00
|
|
|
{
|
2019-03-06 22:56:34 -08:00
|
|
|
type Response = ();
|
|
|
|
type Error = DispatchError;
|
2019-04-08 14:51:16 -07:00
|
|
|
type Future = Dispatcher<T, S, B, X, U>;
|
2018-10-04 20:02:10 -07:00
|
|
|
|
2021-02-06 17:00:40 -08:00
|
|
|
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
2021-12-17 01:29:41 +00:00
|
|
|
self._poll_ready(cx).map_err(|err| {
|
|
|
|
log::error!("HTTP/1 service readiness error: {:?}", err);
|
|
|
|
DispatchError::Service(err)
|
2021-03-29 19:06:16 -07:00
|
|
|
})
|
2018-10-04 20:02:10 -07:00
|
|
|
}
|
|
|
|
|
2021-02-06 17:00:40 -08:00
|
|
|
fn call(&self, (io, addr): (T, Option<net::SocketAddr>)) -> Self::Future {
|
2021-12-07 17:23:34 +00:00
|
|
|
let conn_data = OnConnectData::from_io(&io, self.on_connect_ext.as_deref());
|
|
|
|
Dispatcher::new(io, self.flow.clone(), self.cfg.clone(), addr, conn_data)
|
2018-10-04 20:02:10 -07:00
|
|
|
}
|
|
|
|
}
|