From 5003c00efbdeb8ef76b8137a3d604d7ba4c16d4d Mon Sep 17 00:00:00 2001
From: Nikolay Kim <fafhrd91@gmail.com>
Date: Fri, 30 Nov 2018 11:57:57 -0800
Subject: [PATCH] use new Service and NewService traits

---
 Cargo.toml               |  4 +--
 rustfmt.toml             |  2 +-
 src/client/connector.rs  | 56 ++++++++++++----------------------------
 src/client/pipeline.rs   |  2 +-
 src/client/pool.rs       | 11 ++++----
 src/client/request.rs    |  2 +-
 src/h1/dispatcher.rs     | 14 +++++-----
 src/h1/service.rs        | 34 +++++++++++-------------
 src/service.rs           | 16 +++++-------
 src/test.rs              |  9 +++----
 src/ws/client/service.rs | 13 +++++-----
 src/ws/service.rs        |  8 +++---
 src/ws/transport.rs      | 10 +++----
 13 files changed, 73 insertions(+), 108 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index b2c7c0848..b1dd69ac1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -45,8 +45,8 @@ rust-tls = ["rustls", "actix-net/rust-tls"]
 
 [dependencies]
 actix = "0.7.5"
-actix-net = "0.2.3"
-#actix-net = { git="https://github.com/actix/actix-net.git" }
+#actix-net = "0.3.0"
+actix-net = { git="https://github.com/actix/actix-net.git" }
 
 base64 = "0.9"
 bitflags = "1.0"
diff --git a/rustfmt.toml b/rustfmt.toml
index 4fff285e7..5fcaaca0f 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -1,5 +1,5 @@
 max_width = 89
 reorder_imports = true
 #wrap_comments = true
-fn_args_density = "Compressed"
+#fn_args_density = "Compressed"
 #use_small_heuristics = false
diff --git a/src/client/connector.rs b/src/client/connector.rs
index 42cba9dec..3729ce394 100644
--- a/src/client/connector.rs
+++ b/src/client/connector.rs
@@ -134,11 +134,8 @@ impl Connector {
     /// Finish configuration process and create connector service.
     pub fn service(
         self,
-    ) -> impl Service<
-        Request = Connect,
-        Response = impl Connection,
-        Error = ConnectorError,
-    > + Clone {
+    ) -> impl Service<Connect, Response = impl Connection, Error = ConnectorError> + Clone
+    {
         #[cfg(not(feature = "ssl"))]
         {
             let connector = TimeoutService::new(
@@ -216,7 +213,7 @@ mod connect_impl {
     pub(crate) struct InnerConnector<T, Io>
     where
         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>,
     }
@@ -224,8 +221,7 @@ mod connect_impl {
     impl<T, Io> Clone for InnerConnector<T, Io>
     where
         Io: AsyncRead + AsyncWrite + 'static,
-        T: Service<Request = Connect, Response = (Connect, Io), Error = ConnectorError>
-            + Clone,
+        T: Service<Connect, Response = (Connect, Io), Error = ConnectorError> + Clone,
     {
         fn clone(&self) -> Self {
             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
         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 Error = ConnectorError;
         type Future = Either<
-            <ConnectionPool<T, Io> as Service>::Future,
+            <ConnectionPool<T, Io> as Service<Connect>>::Future,
             FutureResult<IoConnection<Io>, ConnectorError>,
         >;
 
@@ -251,7 +246,7 @@ mod connect_impl {
             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() {
                 Either::B(err(ConnectorError::SslIsNotSupported))
             } else if let Err(e) = req.validate() {
@@ -295,16 +290,8 @@ mod connect_impl {
     where
         Io1: AsyncRead + AsyncWrite + 'static,
         Io2: AsyncRead + AsyncWrite + 'static,
-        T1: Service<
-                Request = Connect,
-                Response = (Connect, Io1),
-                Error = ConnectorError,
-            > + Clone,
-        T2: Service<
-                Request = Connect,
-                Response = (Connect, Io2),
-                Error = ConnectorError,
-            > + Clone,
+        T1: Service<Connect, Response = (Connect, Io1), Error = ConnectorError> + Clone,
+        T2: Service<Connect, Response = (Connect, Io2), Error = ConnectorError> + Clone,
     {
         fn clone(&self) -> Self {
             InnerConnector {
@@ -318,18 +305,9 @@ mod connect_impl {
     where
         Io1: AsyncRead + AsyncWrite + 'static,
         Io2: AsyncRead + AsyncWrite + 'static,
-        T1: Service<
-            Request = Connect,
-            Response = (Connect, Io1),
-            Error = ConnectorError,
-        >,
-        T2: Service<
-            Request = Connect,
-            Response = (Connect, Io2),
-            Error = ConnectorError,
-        >,
+        T1: Service<Connect, Response = (Connect, Io1), Error = ConnectorError>,
+        T2: Service<Connect, Response = (Connect, Io2), Error = ConnectorError>,
     {
-        type Request = Connect;
         type Response = IoEither<IoConnection<Io1>, IoConnection<Io2>>;
         type Error = ConnectorError;
         type Future = Either<
@@ -344,7 +322,7 @@ mod connect_impl {
             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() {
                 Either::A(err(e))
             } else if req.is_secure() {
@@ -364,7 +342,7 @@ mod connect_impl {
     pub(crate) struct InnerConnectorResponseA<T, Io1, Io2>
     where
         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,
         _t: PhantomData<Io2>,
@@ -372,7 +350,7 @@ mod connect_impl {
 
     impl<T, Io1, Io2> Future for InnerConnectorResponseA<T, Io1, Io2>
     where
-        T: Service<Request = Connect, Response = (Connect, Io1), Error = ConnectorError>,
+        T: Service<Connect, Response = (Connect, Io1), Error = ConnectorError>,
         Io1: AsyncRead + AsyncWrite + 'static,
         Io2: AsyncRead + AsyncWrite + 'static,
     {
@@ -390,7 +368,7 @@ mod connect_impl {
     pub(crate) struct InnerConnectorResponseB<T, Io1, Io2>
     where
         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,
         _t: PhantomData<Io1>,
@@ -398,7 +376,7 @@ mod connect_impl {
 
     impl<T, Io1, Io2> Future for InnerConnectorResponseB<T, Io1, Io2>
     where
-        T: Service<Request = Connect, Response = (Connect, Io2), Error = ConnectorError>,
+        T: Service<Connect, Response = (Connect, Io2), Error = ConnectorError>,
         Io1: AsyncRead + AsyncWrite + 'static,
         Io2: AsyncRead + AsyncWrite + 'static,
     {
diff --git a/src/client/pipeline.rs b/src/client/pipeline.rs
index e1d8421e9..e75265507 100644
--- a/src/client/pipeline.rs
+++ b/src/client/pipeline.rs
@@ -21,7 +21,7 @@ pub(crate) fn send_request<T, I, B>(
     connector: &mut T,
 ) -> impl Future<Item = ClientResponse, Error = SendRequestError>
 where
-    T: Service<Request = Connect, Response = I, Error = ConnectorError>,
+    T: Service<Connect, Response = I, Error = ConnectorError>,
     B: MessageBody,
     I: Connection,
 {
diff --git a/src/client/pool.rs b/src/client/pool.rs
index 44008f346..decf80194 100644
--- a/src/client/pool.rs
+++ b/src/client/pool.rs
@@ -47,7 +47,7 @@ pub(crate) struct ConnectionPool<T, Io: AsyncRead + AsyncWrite + 'static>(
 impl<T, Io> ConnectionPool<T, Io>
 where
     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(
         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
     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 Error = ConnectorError;
     type Future = Either<
@@ -100,7 +99,7 @@ where
         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();
 
         // acquire connection
@@ -456,7 +455,7 @@ where
 impl<T, Io> Future for ConnectorPoolSupport<T, Io>
 where
     Io: AsyncRead + AsyncWrite + 'static,
-    T: Service<Request = Connect, Response = (Connect, Io), Error = ConnectorError>,
+    T: Service<Connect, Response = (Connect, Io), Error = ConnectorError>,
     T::Future: 'static,
 {
     type Item = ();
diff --git a/src/client/request.rs b/src/client/request.rs
index dd29d7978..e71c3ffd8 100644
--- a/src/client/request.rs
+++ b/src/client/request.rs
@@ -177,7 +177,7 @@ where
         connector: &mut T,
     ) -> impl Future<Item = ClientResponse, Error = SendRequestError>
     where
-        T: Service<Request = Connect, Response = I, Error = ConnectorError>,
+        T: Service<Connect, Response = I, Error = ConnectorError>,
         I: Connection,
     {
         pipeline::send_request(self.head, self.body, connector)
diff --git a/src/h1/dispatcher.rs b/src/h1/dispatcher.rs
index 48c8e710b..5e2742aa5 100644
--- a/src/h1/dispatcher.rs
+++ b/src/h1/dispatcher.rs
@@ -36,14 +36,14 @@ bitflags! {
 }
 
 /// Dispatcher for HTTP/1.1 protocol
-pub struct Dispatcher<T, S: Service, B: MessageBody>
+pub struct Dispatcher<T, S: Service<Request>, B: MessageBody>
 where
     S::Error: Debug,
 {
     inner: Option<InnerDispatcher<T, S, B>>,
 }
 
-struct InnerDispatcher<T, S: Service, B: MessageBody>
+struct InnerDispatcher<T, S: Service<Request>, B: MessageBody>
 where
     S::Error: Debug,
 {
@@ -67,13 +67,13 @@ enum DispatcherMessage {
     Error(Response<()>),
 }
 
-enum State<S: Service, B: MessageBody> {
+enum State<S: Service<Request>, B: MessageBody> {
     None,
     ServiceCall(S::Future),
     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 {
         if let State::None = self {
             true
@@ -86,7 +86,7 @@ impl<S: Service, B: MessageBody> State<S, B> {
 impl<T, S, B> Dispatcher<T, S, B>
 where
     T: AsyncRead + AsyncWrite,
-    S: Service<Request = Request, Response = Response<B>>,
+    S: Service<Request, Response = Response<B>>,
     S::Error: Debug,
     B: MessageBody,
 {
@@ -140,7 +140,7 @@ where
 impl<T, S, B> InnerDispatcher<T, S, B>
 where
     T: AsyncRead + AsyncWrite,
-    S: Service<Request = Request, Response = Response<B>>,
+    S: Service<Request, Response = Response<B>>,
     S::Error: Debug,
     B: MessageBody,
 {
@@ -463,7 +463,7 @@ where
 impl<T, S, B> Future for Dispatcher<T, S, B>
 where
     T: AsyncRead + AsyncWrite,
-    S: Service<Request = Request, Response = Response<B>>,
+    S: Service<Request, Response = Response<B>>,
     S::Error: Debug,
     B: MessageBody,
 {
diff --git a/src/h1/service.rs b/src/h1/service.rs
index 0f0452ee7..e21d0fb60 100644
--- a/src/h1/service.rs
+++ b/src/h1/service.rs
@@ -27,13 +27,13 @@ pub struct H1Service<T, S, B> {
 
 impl<T, S, B> H1Service<T, S, B>
 where
-    S: NewService<Request = Request, Response = Response<B>> + Clone,
+    S: NewService<Request, Response = Response<B>> + Clone,
     S::Service: Clone,
     S::Error: Debug,
     B: MessageBody,
 {
     /// 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);
 
         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
     T: AsyncRead + AsyncWrite,
-    S: NewService<Request = Request, Response = Response<B>> + Clone,
+    S: NewService<Request, Response = Response<B>> + Clone,
     S::Service: Clone,
     S::Error: Debug,
     B: MessageBody,
 {
-    type Request = T;
     type Response = H1ServiceResult<T>;
     type Error = DispatchError<S::Error>;
     type InitError = S::InitError;
@@ -89,7 +88,7 @@ pub struct H1ServiceBuilder<T, S> {
 
 impl<T, S> H1ServiceBuilder<T, S>
 where
-    S: NewService,
+    S: NewService<Request>,
     S::Service: Clone,
     S::Error: Debug,
 {
@@ -186,7 +185,7 @@ where
     pub fn finish<F, B>(self, service: F) -> H1Service<T, S, B>
     where
         B: MessageBody,
-        F: IntoNewService<S>,
+        F: IntoNewService<S, Request>,
     {
         let cfg = ServiceConfig::new(
             self.keep_alive,
@@ -202,7 +201,7 @@ where
 }
 
 #[doc(hidden)]
-pub struct H1ServiceResponse<T, S: NewService, B> {
+pub struct H1ServiceResponse<T, S: NewService<Request>, B> {
     fut: S::Future,
     cfg: Option<ServiceConfig>,
     _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>
 where
     T: AsyncRead + AsyncWrite,
-    S: NewService<Request = Request, Response = Response<B>>,
+    S: NewService<Request, Response = Response<B>>,
     S::Service: Clone,
     S::Error: Debug,
     B: MessageBody,
@@ -237,7 +236,7 @@ pub struct H1ServiceHandler<T, S, B> {
 
 impl<T, S, B> H1ServiceHandler<T, S, B>
 where
-    S: Service<Request = Request, Response = Response<B>> + Clone,
+    S: Service<Request, Response = Response<B>> + Clone,
     S::Error: Debug,
     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
     T: AsyncRead + AsyncWrite,
-    S: Service<Request = Request, Response = Response<B>> + Clone,
+    S: Service<Request, Response = Response<B>> + Clone,
     S::Error: Debug,
     B: MessageBody,
 {
-    type Request = T;
     type Response = H1ServiceResult<T>;
     type Error = DispatchError<S::Error>;
     type Future = Dispatcher<T, S, B>;
@@ -266,7 +264,7 @@ where
         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())
     }
 }
@@ -290,11 +288,10 @@ where
     }
 }
 
-impl<T> NewService for OneRequest<T>
+impl<T> NewService<T> for OneRequest<T>
 where
     T: AsyncRead + AsyncWrite,
 {
-    type Request = T;
     type Response = (Request, Framed<T, Codec>);
     type Error = ParseError;
     type InitError = ();
@@ -316,11 +313,10 @@ pub struct OneRequestService<T> {
     _t: PhantomData<T>,
 }
 
-impl<T> Service for OneRequestService<T>
+impl<T> Service<T> for OneRequestService<T>
 where
     T: AsyncRead + AsyncWrite,
 {
-    type Request = T;
     type Response = (Request, Framed<T, Codec>);
     type Error = ParseError;
     type Future = OneRequestServiceResponse<T>;
@@ -329,7 +325,7 @@ where
         Ok(Async::Ready(()))
     }
 
-    fn call(&mut self, req: Self::Request) -> Self::Future {
+    fn call(&mut self, req: T) -> Self::Future {
         OneRequestServiceResponse {
             framed: Some(Framed::new(req, Codec::new(self.config.clone()))),
         }
diff --git a/src/service.rs b/src/service.rs
index 6a31b6bb8..aa507acb8 100644
--- a/src/service.rs
+++ b/src/service.rs
@@ -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
     T: AsyncRead + AsyncWrite,
     E: ResponseError,
 {
-    type Request = Result<R, (E, Framed<T, Codec>)>;
     type Response = R;
     type Error = (E, Framed<T, Codec>);
     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
     T: AsyncRead + AsyncWrite,
     E: ResponseError,
 {
-    type Request = Result<R, (E, Framed<T, Codec>)>;
     type Response = R;
     type Error = (E, Framed<T, Codec>);
     type Future = Either<FutureResult<R, (E, Framed<T, Codec>)>, SendErrorFut<T, R, E>>;
@@ -54,7 +52,7 @@ where
         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 {
             Ok(r) => Either::A(ok(r)),
             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
     T: AsyncRead + AsyncWrite,
     B: MessageBody,
 {
-    type Request = (Response<B>, Framed<T, Codec>);
     type Response = Framed<T, Codec>;
     type Error = Error;
     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
     T: AsyncRead + AsyncWrite,
     B: MessageBody,
 {
-    type Request = (Response<B>, Framed<T, Codec>);
     type Response = Framed<T, Codec>;
     type Error = Error;
     type Future = SendResponseFut<T, B>;
@@ -162,7 +158,7 @@ where
         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(());
         SendResponseFut {
             res: Some(Message::Item((res, body.length()))),
diff --git a/src/test.rs b/src/test.rs
index 84a959c41..3d12e344b 100644
--- a/src/test.rs
+++ b/src/test.rs
@@ -306,8 +306,7 @@ impl TestServer {
     pub fn with_factory<F: StreamServiceFactory>(
         factory: F,
     ) -> TestServerRuntime<
-        impl Service<Request = Connect, Response = impl Connection, Error = ConnectorError>
-            + Clone,
+        impl Service<Connect, Response = impl Connection, Error = ConnectorError> + Clone,
     > {
         let (tx, rx) = mpsc::channel();
 
@@ -339,8 +338,8 @@ impl TestServer {
     }
 
     fn new_connector(
-) -> impl Service<Request = Connect, Response = impl Connection, Error = ConnectorError>
-             + Clone {
+) -> impl Service<Connect, Response = impl Connection, Error = ConnectorError> + Clone
+    {
         #[cfg(feature = "ssl")]
         {
             use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
@@ -441,7 +440,7 @@ impl<T> TestServerRuntime<T> {
 
 impl<T> TestServerRuntime<T>
 where
-    T: Service<Request = Connect, Error = ConnectorError> + Clone,
+    T: Service<Connect, Error = ConnectorError> + Clone,
     T::Response: Connection,
 {
     /// Connect to websocket server at a given path
diff --git a/src/ws/client/service.rs b/src/ws/client/service.rs
index 94be59f6e..68f8032e6 100644
--- a/src/ws/client/service.rs
+++ b/src/ws/client/service.rs
@@ -26,7 +26,7 @@ pub type DefaultClient = Client<DefaultConnector>;
 /// WebSocket's client
 pub struct Client<T>
 where
-    T: Service<Error = ConnectorError>,
+    T: Service<TcpConnect, Error = ConnectorError>,
     T::Response: AsyncRead + AsyncWrite,
 {
     connector: T,
@@ -34,7 +34,7 @@ where
 
 impl<T> Client<T>
 where
-    T: Service<Request = TcpConnect, Error = ConnectorError>,
+    T: Service<TcpConnect, Error = ConnectorError>,
     T::Response: AsyncRead + AsyncWrite,
 {
     /// Create new websocket's client factory
@@ -51,7 +51,7 @@ impl Default for Client<DefaultConnector> {
 
 impl<T> Clone for Client<T>
 where
-    T: Service<Request = TcpConnect, Error = ConnectorError> + Clone,
+    T: Service<TcpConnect, Error = ConnectorError> + Clone,
     T::Response: AsyncRead + AsyncWrite,
 {
     fn clone(&self) -> Self {
@@ -61,13 +61,12 @@ where
     }
 }
 
-impl<T> Service for Client<T>
+impl<T> Service<Connect> for Client<T>
 where
-    T: Service<Request = TcpConnect, Error = ConnectorError>,
+    T: Service<TcpConnect, Error = ConnectorError>,
     T::Response: AsyncRead + AsyncWrite + 'static,
     T::Future: 'static,
 {
-    type Request = Connect;
     type Response = Framed<T::Response, Codec>;
     type Error = ClientError;
     type Future = Either<
@@ -79,7 +78,7 @@ where
         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() {
             Either::A(err(e))
         } else if let Some(e) = req.http_err.take() {
diff --git a/src/ws/service.rs b/src/ws/service.rs
index 9cce4d639..118a2244a 100644
--- a/src/ws/service.rs
+++ b/src/ws/service.rs
@@ -20,8 +20,7 @@ impl<T> Default for VerifyWebSockets<T> {
     }
 }
 
-impl<T> NewService for VerifyWebSockets<T> {
-    type Request = (Request, Framed<T, Codec>);
+impl<T> NewService<(Request, Framed<T, Codec>)> for VerifyWebSockets<T> {
     type Response = (Request, Framed<T, Codec>);
     type Error = (HandshakeError, Framed<T, Codec>);
     type InitError = ();
@@ -33,8 +32,7 @@ impl<T> NewService for VerifyWebSockets<T> {
     }
 }
 
-impl<T> Service for VerifyWebSockets<T> {
-    type Request = (Request, Framed<T, Codec>);
+impl<T> Service<(Request, Framed<T, Codec>)> for VerifyWebSockets<T> {
     type Response = (Request, Framed<T, Codec>);
     type Error = (HandshakeError, Framed<T, Codec>);
     type Future = FutureResult<Self::Response, Self::Error>;
@@ -43,7 +41,7 @@ impl<T> Service for VerifyWebSockets<T> {
         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) {
             Err(e) => Err((e, framed)).into_future(),
             Ok(_) => Ok((req, framed)).into_future(),
diff --git a/src/ws/transport.rs b/src/ws/transport.rs
index 102d02b43..8cd79cb03 100644
--- a/src/ws/transport.rs
+++ b/src/ws/transport.rs
@@ -8,7 +8,7 @@ use super::{Codec, Frame, Message};
 
 pub struct Transport<S, T>
 where
-    S: Service,
+    S: Service<Frame, Response = Message>,
     T: AsyncRead + AsyncWrite,
 {
     inner: FramedTransport<S, T, Codec>,
@@ -17,17 +17,17 @@ where
 impl<S, T> Transport<S, T>
 where
     T: AsyncRead + AsyncWrite,
-    S: Service<Request = Frame, Response = Message>,
+    S: Service<Frame, Response = Message>,
     S::Future: '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 {
             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 {
             inner: FramedTransport::new(framed, service),
         }
@@ -37,7 +37,7 @@ where
 impl<S, T> Future for Transport<S, T>
 where
     T: AsyncRead + AsyncWrite,
-    S: Service<Request = Frame, Response = Message>,
+    S: Service<Frame, Response = Message>,
     S::Future: 'static,
     S::Error: 'static,
 {