mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 08:22:59 +01:00
use new Service and NewService traits
This commit is contained in:
parent
d269904fbf
commit
5003c00efb
@ -45,8 +45,8 @@ rust-tls = ["rustls", "actix-net/rust-tls"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix = "0.7.5"
|
actix = "0.7.5"
|
||||||
actix-net = "0.2.3"
|
#actix-net = "0.3.0"
|
||||||
#actix-net = { git="https://github.com/actix/actix-net.git" }
|
actix-net = { git="https://github.com/actix/actix-net.git" }
|
||||||
|
|
||||||
base64 = "0.9"
|
base64 = "0.9"
|
||||||
bitflags = "1.0"
|
bitflags = "1.0"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
max_width = 89
|
max_width = 89
|
||||||
reorder_imports = true
|
reorder_imports = true
|
||||||
#wrap_comments = true
|
#wrap_comments = true
|
||||||
fn_args_density = "Compressed"
|
#fn_args_density = "Compressed"
|
||||||
#use_small_heuristics = false
|
#use_small_heuristics = false
|
||||||
|
@ -134,11 +134,8 @@ impl Connector {
|
|||||||
/// Finish configuration process and create connector service.
|
/// Finish configuration process and create connector service.
|
||||||
pub fn service(
|
pub fn service(
|
||||||
self,
|
self,
|
||||||
) -> impl Service<
|
) -> impl Service<Connect, Response = impl Connection, Error = ConnectorError> + Clone
|
||||||
Request = Connect,
|
{
|
||||||
Response = impl Connection,
|
|
||||||
Error = ConnectorError,
|
|
||||||
> + Clone {
|
|
||||||
#[cfg(not(feature = "ssl"))]
|
#[cfg(not(feature = "ssl"))]
|
||||||
{
|
{
|
||||||
let connector = TimeoutService::new(
|
let connector = TimeoutService::new(
|
||||||
@ -216,7 +213,7 @@ mod connect_impl {
|
|||||||
pub(crate) struct InnerConnector<T, Io>
|
pub(crate) struct InnerConnector<T, Io>
|
||||||
where
|
where
|
||||||
Io: AsyncRead + AsyncWrite + 'static,
|
Io: AsyncRead + AsyncWrite + 'static,
|
||||||
T: Service<Request = Connect, Response = (Connect, Io), Error = ConnectorError>,
|
T: Service<Connect, Response = (Connect, Io), Error = ConnectorError>,
|
||||||
{
|
{
|
||||||
pub(crate) tcp_pool: ConnectionPool<T, Io>,
|
pub(crate) tcp_pool: ConnectionPool<T, Io>,
|
||||||
}
|
}
|
||||||
@ -224,8 +221,7 @@ mod connect_impl {
|
|||||||
impl<T, Io> Clone for InnerConnector<T, Io>
|
impl<T, Io> Clone for InnerConnector<T, Io>
|
||||||
where
|
where
|
||||||
Io: AsyncRead + AsyncWrite + 'static,
|
Io: AsyncRead + AsyncWrite + 'static,
|
||||||
T: Service<Request = Connect, Response = (Connect, Io), Error = ConnectorError>
|
T: Service<Connect, Response = (Connect, Io), Error = ConnectorError> + Clone,
|
||||||
+ Clone,
|
|
||||||
{
|
{
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
InnerConnector {
|
InnerConnector {
|
||||||
@ -234,16 +230,15 @@ mod connect_impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, Io> Service for InnerConnector<T, Io>
|
impl<T, Io> Service<Connect> for InnerConnector<T, Io>
|
||||||
where
|
where
|
||||||
Io: AsyncRead + AsyncWrite + 'static,
|
Io: AsyncRead + AsyncWrite + 'static,
|
||||||
T: Service<Request = Connect, Response = (Connect, Io), Error = ConnectorError>,
|
T: Service<Connect, Response = (Connect, Io), Error = ConnectorError>,
|
||||||
{
|
{
|
||||||
type Request = Connect;
|
|
||||||
type Response = IoConnection<Io>;
|
type Response = IoConnection<Io>;
|
||||||
type Error = ConnectorError;
|
type Error = ConnectorError;
|
||||||
type Future = Either<
|
type Future = Either<
|
||||||
<ConnectionPool<T, Io> as Service>::Future,
|
<ConnectionPool<T, Io> as Service<Connect>>::Future,
|
||||||
FutureResult<IoConnection<Io>, ConnectorError>,
|
FutureResult<IoConnection<Io>, ConnectorError>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
@ -251,7 +246,7 @@ mod connect_impl {
|
|||||||
self.tcp_pool.poll_ready()
|
self.tcp_pool.poll_ready()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, req: Self::Request) -> Self::Future {
|
fn call(&mut self, req: Connect) -> Self::Future {
|
||||||
if req.is_secure() {
|
if req.is_secure() {
|
||||||
Either::B(err(ConnectorError::SslIsNotSupported))
|
Either::B(err(ConnectorError::SslIsNotSupported))
|
||||||
} else if let Err(e) = req.validate() {
|
} else if let Err(e) = req.validate() {
|
||||||
@ -295,16 +290,8 @@ mod connect_impl {
|
|||||||
where
|
where
|
||||||
Io1: AsyncRead + AsyncWrite + 'static,
|
Io1: AsyncRead + AsyncWrite + 'static,
|
||||||
Io2: AsyncRead + AsyncWrite + 'static,
|
Io2: AsyncRead + AsyncWrite + 'static,
|
||||||
T1: Service<
|
T1: Service<Connect, Response = (Connect, Io1), Error = ConnectorError> + Clone,
|
||||||
Request = Connect,
|
T2: Service<Connect, Response = (Connect, Io2), Error = ConnectorError> + Clone,
|
||||||
Response = (Connect, Io1),
|
|
||||||
Error = ConnectorError,
|
|
||||||
> + Clone,
|
|
||||||
T2: Service<
|
|
||||||
Request = Connect,
|
|
||||||
Response = (Connect, Io2),
|
|
||||||
Error = ConnectorError,
|
|
||||||
> + Clone,
|
|
||||||
{
|
{
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
InnerConnector {
|
InnerConnector {
|
||||||
@ -318,18 +305,9 @@ mod connect_impl {
|
|||||||
where
|
where
|
||||||
Io1: AsyncRead + AsyncWrite + 'static,
|
Io1: AsyncRead + AsyncWrite + 'static,
|
||||||
Io2: AsyncRead + AsyncWrite + 'static,
|
Io2: AsyncRead + AsyncWrite + 'static,
|
||||||
T1: Service<
|
T1: Service<Connect, Response = (Connect, Io1), Error = ConnectorError>,
|
||||||
Request = Connect,
|
T2: Service<Connect, Response = (Connect, Io2), Error = ConnectorError>,
|
||||||
Response = (Connect, Io1),
|
|
||||||
Error = ConnectorError,
|
|
||||||
>,
|
|
||||||
T2: Service<
|
|
||||||
Request = Connect,
|
|
||||||
Response = (Connect, Io2),
|
|
||||||
Error = ConnectorError,
|
|
||||||
>,
|
|
||||||
{
|
{
|
||||||
type Request = Connect;
|
|
||||||
type Response = IoEither<IoConnection<Io1>, IoConnection<Io2>>;
|
type Response = IoEither<IoConnection<Io1>, IoConnection<Io2>>;
|
||||||
type Error = ConnectorError;
|
type Error = ConnectorError;
|
||||||
type Future = Either<
|
type Future = Either<
|
||||||
@ -344,7 +322,7 @@ mod connect_impl {
|
|||||||
self.tcp_pool.poll_ready()
|
self.tcp_pool.poll_ready()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, req: Self::Request) -> Self::Future {
|
fn call(&mut self, req: Connect) -> Self::Future {
|
||||||
if let Err(e) = req.validate() {
|
if let Err(e) = req.validate() {
|
||||||
Either::A(err(e))
|
Either::A(err(e))
|
||||||
} else if req.is_secure() {
|
} else if req.is_secure() {
|
||||||
@ -364,7 +342,7 @@ mod connect_impl {
|
|||||||
pub(crate) struct InnerConnectorResponseA<T, Io1, Io2>
|
pub(crate) struct InnerConnectorResponseA<T, Io1, Io2>
|
||||||
where
|
where
|
||||||
Io1: AsyncRead + AsyncWrite + 'static,
|
Io1: AsyncRead + AsyncWrite + 'static,
|
||||||
T: Service<Request = Connect, Response = (Connect, Io1), Error = ConnectorError>,
|
T: Service<Connect, Response = (Connect, Io1), Error = ConnectorError>,
|
||||||
{
|
{
|
||||||
fut: <ConnectionPool<T, Io1> as Service>::Future,
|
fut: <ConnectionPool<T, Io1> as Service>::Future,
|
||||||
_t: PhantomData<Io2>,
|
_t: PhantomData<Io2>,
|
||||||
@ -372,7 +350,7 @@ mod connect_impl {
|
|||||||
|
|
||||||
impl<T, Io1, Io2> Future for InnerConnectorResponseA<T, Io1, Io2>
|
impl<T, Io1, Io2> Future for InnerConnectorResponseA<T, Io1, Io2>
|
||||||
where
|
where
|
||||||
T: Service<Request = Connect, Response = (Connect, Io1), Error = ConnectorError>,
|
T: Service<Connect, Response = (Connect, Io1), Error = ConnectorError>,
|
||||||
Io1: AsyncRead + AsyncWrite + 'static,
|
Io1: AsyncRead + AsyncWrite + 'static,
|
||||||
Io2: AsyncRead + AsyncWrite + 'static,
|
Io2: AsyncRead + AsyncWrite + 'static,
|
||||||
{
|
{
|
||||||
@ -390,7 +368,7 @@ mod connect_impl {
|
|||||||
pub(crate) struct InnerConnectorResponseB<T, Io1, Io2>
|
pub(crate) struct InnerConnectorResponseB<T, Io1, Io2>
|
||||||
where
|
where
|
||||||
Io2: AsyncRead + AsyncWrite + 'static,
|
Io2: AsyncRead + AsyncWrite + 'static,
|
||||||
T: Service<Request = Connect, Response = (Connect, Io2), Error = ConnectorError>,
|
T: Service<Connect, Response = (Connect, Io2), Error = ConnectorError>,
|
||||||
{
|
{
|
||||||
fut: <ConnectionPool<T, Io2> as Service>::Future,
|
fut: <ConnectionPool<T, Io2> as Service>::Future,
|
||||||
_t: PhantomData<Io1>,
|
_t: PhantomData<Io1>,
|
||||||
@ -398,7 +376,7 @@ mod connect_impl {
|
|||||||
|
|
||||||
impl<T, Io1, Io2> Future for InnerConnectorResponseB<T, Io1, Io2>
|
impl<T, Io1, Io2> Future for InnerConnectorResponseB<T, Io1, Io2>
|
||||||
where
|
where
|
||||||
T: Service<Request = Connect, Response = (Connect, Io2), Error = ConnectorError>,
|
T: Service<Connect, Response = (Connect, Io2), Error = ConnectorError>,
|
||||||
Io1: AsyncRead + AsyncWrite + 'static,
|
Io1: AsyncRead + AsyncWrite + 'static,
|
||||||
Io2: AsyncRead + AsyncWrite + 'static,
|
Io2: AsyncRead + AsyncWrite + 'static,
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,7 @@ pub(crate) fn send_request<T, I, B>(
|
|||||||
connector: &mut T,
|
connector: &mut T,
|
||||||
) -> impl Future<Item = ClientResponse, Error = SendRequestError>
|
) -> impl Future<Item = ClientResponse, Error = SendRequestError>
|
||||||
where
|
where
|
||||||
T: Service<Request = Connect, Response = I, Error = ConnectorError>,
|
T: Service<Connect, Response = I, Error = ConnectorError>,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
I: Connection,
|
I: Connection,
|
||||||
{
|
{
|
||||||
|
@ -47,7 +47,7 @@ pub(crate) struct ConnectionPool<T, Io: AsyncRead + AsyncWrite + 'static>(
|
|||||||
impl<T, Io> ConnectionPool<T, Io>
|
impl<T, Io> ConnectionPool<T, Io>
|
||||||
where
|
where
|
||||||
Io: AsyncRead + AsyncWrite + 'static,
|
Io: AsyncRead + AsyncWrite + 'static,
|
||||||
T: Service<Request = Connect, Response = (Connect, Io), Error = ConnectorError>,
|
T: Service<Connect, Response = (Connect, Io), Error = ConnectorError>,
|
||||||
{
|
{
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
connector: T,
|
connector: T,
|
||||||
@ -83,12 +83,11 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, Io> Service for ConnectionPool<T, Io>
|
impl<T, Io> Service<Connect> for ConnectionPool<T, Io>
|
||||||
where
|
where
|
||||||
Io: AsyncRead + AsyncWrite + 'static,
|
Io: AsyncRead + AsyncWrite + 'static,
|
||||||
T: Service<Request = Connect, Response = (Connect, Io), Error = ConnectorError>,
|
T: Service<Connect, Response = (Connect, Io), Error = ConnectorError>,
|
||||||
{
|
{
|
||||||
type Request = Connect;
|
|
||||||
type Response = IoConnection<Io>;
|
type Response = IoConnection<Io>;
|
||||||
type Error = ConnectorError;
|
type Error = ConnectorError;
|
||||||
type Future = Either<
|
type Future = Either<
|
||||||
@ -100,7 +99,7 @@ where
|
|||||||
self.0.poll_ready()
|
self.0.poll_ready()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, req: Self::Request) -> Self::Future {
|
fn call(&mut self, req: Connect) -> Self::Future {
|
||||||
let key = req.key();
|
let key = req.key();
|
||||||
|
|
||||||
// acquire connection
|
// acquire connection
|
||||||
@ -456,7 +455,7 @@ where
|
|||||||
impl<T, Io> Future for ConnectorPoolSupport<T, Io>
|
impl<T, Io> Future for ConnectorPoolSupport<T, Io>
|
||||||
where
|
where
|
||||||
Io: AsyncRead + AsyncWrite + 'static,
|
Io: AsyncRead + AsyncWrite + 'static,
|
||||||
T: Service<Request = Connect, Response = (Connect, Io), Error = ConnectorError>,
|
T: Service<Connect, Response = (Connect, Io), Error = ConnectorError>,
|
||||||
T::Future: 'static,
|
T::Future: 'static,
|
||||||
{
|
{
|
||||||
type Item = ();
|
type Item = ();
|
||||||
|
@ -177,7 +177,7 @@ where
|
|||||||
connector: &mut T,
|
connector: &mut T,
|
||||||
) -> impl Future<Item = ClientResponse, Error = SendRequestError>
|
) -> impl Future<Item = ClientResponse, Error = SendRequestError>
|
||||||
where
|
where
|
||||||
T: Service<Request = Connect, Response = I, Error = ConnectorError>,
|
T: Service<Connect, Response = I, Error = ConnectorError>,
|
||||||
I: Connection,
|
I: Connection,
|
||||||
{
|
{
|
||||||
pipeline::send_request(self.head, self.body, connector)
|
pipeline::send_request(self.head, self.body, connector)
|
||||||
|
@ -36,14 +36,14 @@ bitflags! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Dispatcher for HTTP/1.1 protocol
|
/// Dispatcher for HTTP/1.1 protocol
|
||||||
pub struct Dispatcher<T, S: Service, B: MessageBody>
|
pub struct Dispatcher<T, S: Service<Request>, B: MessageBody>
|
||||||
where
|
where
|
||||||
S::Error: Debug,
|
S::Error: Debug,
|
||||||
{
|
{
|
||||||
inner: Option<InnerDispatcher<T, S, B>>,
|
inner: Option<InnerDispatcher<T, S, B>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct InnerDispatcher<T, S: Service, B: MessageBody>
|
struct InnerDispatcher<T, S: Service<Request>, B: MessageBody>
|
||||||
where
|
where
|
||||||
S::Error: Debug,
|
S::Error: Debug,
|
||||||
{
|
{
|
||||||
@ -67,13 +67,13 @@ enum DispatcherMessage {
|
|||||||
Error(Response<()>),
|
Error(Response<()>),
|
||||||
}
|
}
|
||||||
|
|
||||||
enum State<S: Service, B: MessageBody> {
|
enum State<S: Service<Request>, B: MessageBody> {
|
||||||
None,
|
None,
|
||||||
ServiceCall(S::Future),
|
ServiceCall(S::Future),
|
||||||
SendPayload(ResponseBody<B>),
|
SendPayload(ResponseBody<B>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Service, B: MessageBody> State<S, B> {
|
impl<S: Service<Request>, B: MessageBody> State<S, B> {
|
||||||
fn is_empty(&self) -> bool {
|
fn is_empty(&self) -> bool {
|
||||||
if let State::None = self {
|
if let State::None = self {
|
||||||
true
|
true
|
||||||
@ -86,7 +86,7 @@ impl<S: Service, B: MessageBody> State<S, B> {
|
|||||||
impl<T, S, B> Dispatcher<T, S, B>
|
impl<T, S, B> Dispatcher<T, S, B>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
S: Service<Request = Request, Response = Response<B>>,
|
S: Service<Request, Response = Response<B>>,
|
||||||
S::Error: Debug,
|
S::Error: Debug,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
{
|
{
|
||||||
@ -140,7 +140,7 @@ where
|
|||||||
impl<T, S, B> InnerDispatcher<T, S, B>
|
impl<T, S, B> InnerDispatcher<T, S, B>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
S: Service<Request = Request, Response = Response<B>>,
|
S: Service<Request, Response = Response<B>>,
|
||||||
S::Error: Debug,
|
S::Error: Debug,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
{
|
{
|
||||||
@ -463,7 +463,7 @@ where
|
|||||||
impl<T, S, B> Future for Dispatcher<T, S, B>
|
impl<T, S, B> Future for Dispatcher<T, S, B>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
S: Service<Request = Request, Response = Response<B>>,
|
S: Service<Request, Response = Response<B>>,
|
||||||
S::Error: Debug,
|
S::Error: Debug,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
{
|
{
|
||||||
|
@ -27,13 +27,13 @@ pub struct H1Service<T, S, B> {
|
|||||||
|
|
||||||
impl<T, S, B> H1Service<T, S, B>
|
impl<T, S, B> H1Service<T, S, B>
|
||||||
where
|
where
|
||||||
S: NewService<Request = Request, Response = Response<B>> + Clone,
|
S: NewService<Request, Response = Response<B>> + Clone,
|
||||||
S::Service: Clone,
|
S::Service: Clone,
|
||||||
S::Error: Debug,
|
S::Error: Debug,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
{
|
{
|
||||||
/// Create new `HttpService` instance.
|
/// Create new `HttpService` instance.
|
||||||
pub fn new<F: IntoNewService<S>>(service: F) -> Self {
|
pub fn new<F: IntoNewService<S, Request>>(service: F) -> Self {
|
||||||
let cfg = ServiceConfig::new(KeepAlive::Timeout(5), 5000, 0);
|
let cfg = ServiceConfig::new(KeepAlive::Timeout(5), 5000, 0);
|
||||||
|
|
||||||
H1Service {
|
H1Service {
|
||||||
@ -49,15 +49,14 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, S, B> NewService for H1Service<T, S, B>
|
impl<T, S, B> NewService<T> for H1Service<T, S, B>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
S: NewService<Request = Request, Response = Response<B>> + Clone,
|
S: NewService<Request, Response = Response<B>> + Clone,
|
||||||
S::Service: Clone,
|
S::Service: Clone,
|
||||||
S::Error: Debug,
|
S::Error: Debug,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
{
|
{
|
||||||
type Request = T;
|
|
||||||
type Response = H1ServiceResult<T>;
|
type Response = H1ServiceResult<T>;
|
||||||
type Error = DispatchError<S::Error>;
|
type Error = DispatchError<S::Error>;
|
||||||
type InitError = S::InitError;
|
type InitError = S::InitError;
|
||||||
@ -89,7 +88,7 @@ pub struct H1ServiceBuilder<T, S> {
|
|||||||
|
|
||||||
impl<T, S> H1ServiceBuilder<T, S>
|
impl<T, S> H1ServiceBuilder<T, S>
|
||||||
where
|
where
|
||||||
S: NewService,
|
S: NewService<Request>,
|
||||||
S::Service: Clone,
|
S::Service: Clone,
|
||||||
S::Error: Debug,
|
S::Error: Debug,
|
||||||
{
|
{
|
||||||
@ -186,7 +185,7 @@ where
|
|||||||
pub fn finish<F, B>(self, service: F) -> H1Service<T, S, B>
|
pub fn finish<F, B>(self, service: F) -> H1Service<T, S, B>
|
||||||
where
|
where
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
F: IntoNewService<S>,
|
F: IntoNewService<S, Request>,
|
||||||
{
|
{
|
||||||
let cfg = ServiceConfig::new(
|
let cfg = ServiceConfig::new(
|
||||||
self.keep_alive,
|
self.keep_alive,
|
||||||
@ -202,7 +201,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct H1ServiceResponse<T, S: NewService, B> {
|
pub struct H1ServiceResponse<T, S: NewService<Request>, B> {
|
||||||
fut: S::Future,
|
fut: S::Future,
|
||||||
cfg: Option<ServiceConfig>,
|
cfg: Option<ServiceConfig>,
|
||||||
_t: PhantomData<(T, B)>,
|
_t: PhantomData<(T, B)>,
|
||||||
@ -211,7 +210,7 @@ pub struct H1ServiceResponse<T, S: NewService, B> {
|
|||||||
impl<T, S, B> Future for H1ServiceResponse<T, S, B>
|
impl<T, S, B> Future for H1ServiceResponse<T, S, B>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
S: NewService<Request = Request, Response = Response<B>>,
|
S: NewService<Request, Response = Response<B>>,
|
||||||
S::Service: Clone,
|
S::Service: Clone,
|
||||||
S::Error: Debug,
|
S::Error: Debug,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
@ -237,7 +236,7 @@ pub struct H1ServiceHandler<T, S, B> {
|
|||||||
|
|
||||||
impl<T, S, B> H1ServiceHandler<T, S, B>
|
impl<T, S, B> H1ServiceHandler<T, S, B>
|
||||||
where
|
where
|
||||||
S: Service<Request = Request, Response = Response<B>> + Clone,
|
S: Service<Request, Response = Response<B>> + Clone,
|
||||||
S::Error: Debug,
|
S::Error: Debug,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
{
|
{
|
||||||
@ -250,14 +249,13 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, S, B> Service for H1ServiceHandler<T, S, B>
|
impl<T, S, B> Service<T> for H1ServiceHandler<T, S, B>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
S: Service<Request = Request, Response = Response<B>> + Clone,
|
S: Service<Request, Response = Response<B>> + Clone,
|
||||||
S::Error: Debug,
|
S::Error: Debug,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
{
|
{
|
||||||
type Request = T;
|
|
||||||
type Response = H1ServiceResult<T>;
|
type Response = H1ServiceResult<T>;
|
||||||
type Error = DispatchError<S::Error>;
|
type Error = DispatchError<S::Error>;
|
||||||
type Future = Dispatcher<T, S, B>;
|
type Future = Dispatcher<T, S, B>;
|
||||||
@ -266,7 +264,7 @@ where
|
|||||||
self.srv.poll_ready().map_err(DispatchError::Service)
|
self.srv.poll_ready().map_err(DispatchError::Service)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, req: Self::Request) -> Self::Future {
|
fn call(&mut self, req: T) -> Self::Future {
|
||||||
Dispatcher::new(req, self.cfg.clone(), self.srv.clone())
|
Dispatcher::new(req, self.cfg.clone(), self.srv.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -290,11 +288,10 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> NewService for OneRequest<T>
|
impl<T> NewService<T> for OneRequest<T>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
{
|
{
|
||||||
type Request = T;
|
|
||||||
type Response = (Request, Framed<T, Codec>);
|
type Response = (Request, Framed<T, Codec>);
|
||||||
type Error = ParseError;
|
type Error = ParseError;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
@ -316,11 +313,10 @@ pub struct OneRequestService<T> {
|
|||||||
_t: PhantomData<T>,
|
_t: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Service for OneRequestService<T>
|
impl<T> Service<T> for OneRequestService<T>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
{
|
{
|
||||||
type Request = T;
|
|
||||||
type Response = (Request, Framed<T, Codec>);
|
type Response = (Request, Framed<T, Codec>);
|
||||||
type Error = ParseError;
|
type Error = ParseError;
|
||||||
type Future = OneRequestServiceResponse<T>;
|
type Future = OneRequestServiceResponse<T>;
|
||||||
@ -329,7 +325,7 @@ where
|
|||||||
Ok(Async::Ready(()))
|
Ok(Async::Ready(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, req: Self::Request) -> Self::Future {
|
fn call(&mut self, req: T) -> Self::Future {
|
||||||
OneRequestServiceResponse {
|
OneRequestServiceResponse {
|
||||||
framed: Some(Framed::new(req, Codec::new(self.config.clone()))),
|
framed: Some(Framed::new(req, Codec::new(self.config.clone()))),
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,11 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, R, E> NewService for SendError<T, R, E>
|
impl<T, R, E> NewService<Result<R, (E, Framed<T, Codec>)>> for SendError<T, R, E>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
E: ResponseError,
|
E: ResponseError,
|
||||||
{
|
{
|
||||||
type Request = Result<R, (E, Framed<T, Codec>)>;
|
|
||||||
type Response = R;
|
type Response = R;
|
||||||
type Error = (E, Framed<T, Codec>);
|
type Error = (E, Framed<T, Codec>);
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
@ -40,12 +39,11 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, R, E> Service for SendError<T, R, E>
|
impl<T, R, E> Service<Result<R, (E, Framed<T, Codec>)>> for SendError<T, R, E>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
E: ResponseError,
|
E: ResponseError,
|
||||||
{
|
{
|
||||||
type Request = Result<R, (E, Framed<T, Codec>)>;
|
|
||||||
type Response = R;
|
type Response = R;
|
||||||
type Error = (E, Framed<T, Codec>);
|
type Error = (E, Framed<T, Codec>);
|
||||||
type Future = Either<FutureResult<R, (E, Framed<T, Codec>)>, SendErrorFut<T, R, E>>;
|
type Future = Either<FutureResult<R, (E, Framed<T, Codec>)>, SendErrorFut<T, R, E>>;
|
||||||
@ -54,7 +52,7 @@ where
|
|||||||
Ok(Async::Ready(()))
|
Ok(Async::Ready(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, req: Self::Request) -> Self::Future {
|
fn call(&mut self, req: Result<R, (E, Framed<T, Codec>)>) -> Self::Future {
|
||||||
match req {
|
match req {
|
||||||
Ok(r) => Either::A(ok(r)),
|
Ok(r) => Either::A(ok(r)),
|
||||||
Err((e, framed)) => {
|
Err((e, framed)) => {
|
||||||
@ -131,12 +129,11 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, B> NewService for SendResponse<T, B>
|
impl<T, B> NewService<(Response<B>, Framed<T, Codec>)> for SendResponse<T, B>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
{
|
{
|
||||||
type Request = (Response<B>, Framed<T, Codec>);
|
|
||||||
type Response = Framed<T, Codec>;
|
type Response = Framed<T, Codec>;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
@ -148,12 +145,11 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, B> Service for SendResponse<T, B>
|
impl<T, B> Service<(Response<B>, Framed<T, Codec>)> for SendResponse<T, B>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
{
|
{
|
||||||
type Request = (Response<B>, Framed<T, Codec>);
|
|
||||||
type Response = Framed<T, Codec>;
|
type Response = Framed<T, Codec>;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = SendResponseFut<T, B>;
|
type Future = SendResponseFut<T, B>;
|
||||||
@ -162,7 +158,7 @@ where
|
|||||||
Ok(Async::Ready(()))
|
Ok(Async::Ready(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, (res, framed): Self::Request) -> Self::Future {
|
fn call(&mut self, (res, framed): (Response<B>, Framed<T, Codec>)) -> Self::Future {
|
||||||
let (res, body) = res.replace_body(());
|
let (res, body) = res.replace_body(());
|
||||||
SendResponseFut {
|
SendResponseFut {
|
||||||
res: Some(Message::Item((res, body.length()))),
|
res: Some(Message::Item((res, body.length()))),
|
||||||
|
@ -306,8 +306,7 @@ impl TestServer {
|
|||||||
pub fn with_factory<F: StreamServiceFactory>(
|
pub fn with_factory<F: StreamServiceFactory>(
|
||||||
factory: F,
|
factory: F,
|
||||||
) -> TestServerRuntime<
|
) -> TestServerRuntime<
|
||||||
impl Service<Request = Connect, Response = impl Connection, Error = ConnectorError>
|
impl Service<Connect, Response = impl Connection, Error = ConnectorError> + Clone,
|
||||||
+ Clone,
|
|
||||||
> {
|
> {
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
|
|
||||||
@ -339,8 +338,8 @@ impl TestServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn new_connector(
|
fn new_connector(
|
||||||
) -> impl Service<Request = Connect, Response = impl Connection, Error = ConnectorError>
|
) -> impl Service<Connect, Response = impl Connection, Error = ConnectorError> + Clone
|
||||||
+ Clone {
|
{
|
||||||
#[cfg(feature = "ssl")]
|
#[cfg(feature = "ssl")]
|
||||||
{
|
{
|
||||||
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
|
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
|
||||||
@ -441,7 +440,7 @@ impl<T> TestServerRuntime<T> {
|
|||||||
|
|
||||||
impl<T> TestServerRuntime<T>
|
impl<T> TestServerRuntime<T>
|
||||||
where
|
where
|
||||||
T: Service<Request = Connect, Error = ConnectorError> + Clone,
|
T: Service<Connect, Error = ConnectorError> + Clone,
|
||||||
T::Response: Connection,
|
T::Response: Connection,
|
||||||
{
|
{
|
||||||
/// Connect to websocket server at a given path
|
/// Connect to websocket server at a given path
|
||||||
|
@ -26,7 +26,7 @@ pub type DefaultClient = Client<DefaultConnector>;
|
|||||||
/// WebSocket's client
|
/// WebSocket's client
|
||||||
pub struct Client<T>
|
pub struct Client<T>
|
||||||
where
|
where
|
||||||
T: Service<Error = ConnectorError>,
|
T: Service<TcpConnect, Error = ConnectorError>,
|
||||||
T::Response: AsyncRead + AsyncWrite,
|
T::Response: AsyncRead + AsyncWrite,
|
||||||
{
|
{
|
||||||
connector: T,
|
connector: T,
|
||||||
@ -34,7 +34,7 @@ where
|
|||||||
|
|
||||||
impl<T> Client<T>
|
impl<T> Client<T>
|
||||||
where
|
where
|
||||||
T: Service<Request = TcpConnect, Error = ConnectorError>,
|
T: Service<TcpConnect, Error = ConnectorError>,
|
||||||
T::Response: AsyncRead + AsyncWrite,
|
T::Response: AsyncRead + AsyncWrite,
|
||||||
{
|
{
|
||||||
/// Create new websocket's client factory
|
/// Create new websocket's client factory
|
||||||
@ -51,7 +51,7 @@ impl Default for Client<DefaultConnector> {
|
|||||||
|
|
||||||
impl<T> Clone for Client<T>
|
impl<T> Clone for Client<T>
|
||||||
where
|
where
|
||||||
T: Service<Request = TcpConnect, Error = ConnectorError> + Clone,
|
T: Service<TcpConnect, Error = ConnectorError> + Clone,
|
||||||
T::Response: AsyncRead + AsyncWrite,
|
T::Response: AsyncRead + AsyncWrite,
|
||||||
{
|
{
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
@ -61,13 +61,12 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Service for Client<T>
|
impl<T> Service<Connect> for Client<T>
|
||||||
where
|
where
|
||||||
T: Service<Request = TcpConnect, Error = ConnectorError>,
|
T: Service<TcpConnect, Error = ConnectorError>,
|
||||||
T::Response: AsyncRead + AsyncWrite + 'static,
|
T::Response: AsyncRead + AsyncWrite + 'static,
|
||||||
T::Future: 'static,
|
T::Future: 'static,
|
||||||
{
|
{
|
||||||
type Request = Connect;
|
|
||||||
type Response = Framed<T::Response, Codec>;
|
type Response = Framed<T::Response, Codec>;
|
||||||
type Error = ClientError;
|
type Error = ClientError;
|
||||||
type Future = Either<
|
type Future = Either<
|
||||||
@ -79,7 +78,7 @@ where
|
|||||||
self.connector.poll_ready().map_err(ClientError::from)
|
self.connector.poll_ready().map_err(ClientError::from)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, mut req: Self::Request) -> Self::Future {
|
fn call(&mut self, mut req: Connect) -> Self::Future {
|
||||||
if let Some(e) = req.err.take() {
|
if let Some(e) = req.err.take() {
|
||||||
Either::A(err(e))
|
Either::A(err(e))
|
||||||
} else if let Some(e) = req.http_err.take() {
|
} else if let Some(e) = req.http_err.take() {
|
||||||
|
@ -20,8 +20,7 @@ impl<T> Default for VerifyWebSockets<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> NewService for VerifyWebSockets<T> {
|
impl<T> NewService<(Request, Framed<T, Codec>)> for VerifyWebSockets<T> {
|
||||||
type Request = (Request, Framed<T, Codec>);
|
|
||||||
type Response = (Request, Framed<T, Codec>);
|
type Response = (Request, Framed<T, Codec>);
|
||||||
type Error = (HandshakeError, Framed<T, Codec>);
|
type Error = (HandshakeError, Framed<T, Codec>);
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
@ -33,8 +32,7 @@ impl<T> NewService for VerifyWebSockets<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Service for VerifyWebSockets<T> {
|
impl<T> Service<(Request, Framed<T, Codec>)> for VerifyWebSockets<T> {
|
||||||
type Request = (Request, Framed<T, Codec>);
|
|
||||||
type Response = (Request, Framed<T, Codec>);
|
type Response = (Request, Framed<T, Codec>);
|
||||||
type Error = (HandshakeError, Framed<T, Codec>);
|
type Error = (HandshakeError, Framed<T, Codec>);
|
||||||
type Future = FutureResult<Self::Response, Self::Error>;
|
type Future = FutureResult<Self::Response, Self::Error>;
|
||||||
@ -43,7 +41,7 @@ impl<T> Service for VerifyWebSockets<T> {
|
|||||||
Ok(Async::Ready(()))
|
Ok(Async::Ready(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call(&mut self, (req, framed): Self::Request) -> Self::Future {
|
fn call(&mut self, (req, framed): (Request, Framed<T, Codec>)) -> Self::Future {
|
||||||
match verify_handshake(&req) {
|
match verify_handshake(&req) {
|
||||||
Err(e) => Err((e, framed)).into_future(),
|
Err(e) => Err((e, framed)).into_future(),
|
||||||
Ok(_) => Ok((req, framed)).into_future(),
|
Ok(_) => Ok((req, framed)).into_future(),
|
||||||
|
@ -8,7 +8,7 @@ use super::{Codec, Frame, Message};
|
|||||||
|
|
||||||
pub struct Transport<S, T>
|
pub struct Transport<S, T>
|
||||||
where
|
where
|
||||||
S: Service,
|
S: Service<Frame, Response = Message>,
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
{
|
{
|
||||||
inner: FramedTransport<S, T, Codec>,
|
inner: FramedTransport<S, T, Codec>,
|
||||||
@ -17,17 +17,17 @@ where
|
|||||||
impl<S, T> Transport<S, T>
|
impl<S, T> Transport<S, T>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
S: Service<Request = Frame, Response = Message>,
|
S: Service<Frame, Response = Message>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
S::Error: 'static,
|
S::Error: 'static,
|
||||||
{
|
{
|
||||||
pub fn new<F: IntoService<S>>(io: T, service: F) -> Self {
|
pub fn new<F: IntoService<S, Frame>>(io: T, service: F) -> Self {
|
||||||
Transport {
|
Transport {
|
||||||
inner: FramedTransport::new(Framed::new(io, Codec::new()), service),
|
inner: FramedTransport::new(Framed::new(io, Codec::new()), service),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with<F: IntoService<S>>(framed: Framed<T, Codec>, service: F) -> Self {
|
pub fn with<F: IntoService<S, Frame>>(framed: Framed<T, Codec>, service: F) -> Self {
|
||||||
Transport {
|
Transport {
|
||||||
inner: FramedTransport::new(framed, service),
|
inner: FramedTransport::new(framed, service),
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ where
|
|||||||
impl<S, T> Future for Transport<S, T>
|
impl<S, T> Future for Transport<S, T>
|
||||||
where
|
where
|
||||||
T: AsyncRead + AsyncWrite,
|
T: AsyncRead + AsyncWrite,
|
||||||
S: Service<Request = Frame, Response = Message>,
|
S: Service<Frame, Response = Message>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
S::Error: 'static,
|
S::Error: 'static,
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user