1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 16:02:59 +01:00

update actix-service

This commit is contained in:
Nikolay Kim 2019-03-05 09:30:11 -08:00
parent 3a456ec148
commit ce0b172598
14 changed files with 105 additions and 133 deletions

View File

@ -37,10 +37,14 @@ session = ["cookie/secure"]
ssl = ["openssl", "actix-connector/ssl"] ssl = ["openssl", "actix-connector/ssl"]
[dependencies] [dependencies]
actix-service = "0.3.2" #actix-service = "0.3.2"
actix-codec = "0.1.0" actix-codec = "0.1.0"
actix-connector = "0.3.0" #actix-connector = "0.3.0"
actix-utils = "0.3.1" #actix-utils = "0.3.1"
actix-connector = { git="https://github.com/actix/actix-net.git" }
actix-service = { git="https://github.com/actix/actix-net.git" }
actix-utils = { git="https://github.com/actix/actix-net.git" }
base64 = "0.10" base64 = "0.10"
backtrace = "0.3" backtrace = "0.3"
@ -80,7 +84,8 @@ openssl = { version="0.10", optional = true }
actix-rt = "0.1.0" actix-rt = "0.1.0"
#actix-server = { version = "0.3.0", features=["ssl"] } #actix-server = { version = "0.3.0", features=["ssl"] }
actix-server = { git="https://github.com/actix/actix-net.git", features=["ssl"] } actix-server = { git="https://github.com/actix/actix-net.git", features=["ssl"] }
actix-connector = { version = "0.3.0", features=["ssl"] } #actix-connector = { version = "0.3.0", features=["ssl"] }
actix-connector = { git="https://github.com/actix/actix-net.git", features=["ssl"] }
actix-http-test = { path="test-server", features=["ssl"] } actix-http-test = { path="test-server", features=["ssl"] }
env_logger = "0.6" env_logger = "0.6"
serde_derive = "1.0" serde_derive = "1.0"

View File

@ -133,11 +133,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(
@ -314,12 +311,12 @@ mod connect_impl {
Io1: AsyncRead + AsyncWrite + 'static, Io1: AsyncRead + AsyncWrite + 'static,
Io2: AsyncRead + AsyncWrite + 'static, Io2: AsyncRead + AsyncWrite + 'static,
T1: Service< T1: Service<
Request = Connect, Connect,
Response = (Connect, Io1, Protocol), Response = (Connect, Io1, Protocol),
Error = ConnectorError, Error = ConnectorError,
>, >,
T2: Service< T2: Service<
Request = Connect, Connect,
Response = (Connect, Io2, Protocol), Response = (Connect, Io2, Protocol),
Error = ConnectorError, Error = ConnectorError,
>, >,
@ -333,12 +330,12 @@ mod connect_impl {
Io1: AsyncRead + AsyncWrite + 'static, Io1: AsyncRead + AsyncWrite + 'static,
Io2: AsyncRead + AsyncWrite + 'static, Io2: AsyncRead + AsyncWrite + 'static,
T1: Service< T1: Service<
Request = Connect, Connect,
Response = (Connect, Io1, Protocol), Response = (Connect, Io1, Protocol),
Error = ConnectorError, Error = ConnectorError,
> + Clone, > + Clone,
T2: Service< T2: Service<
Request = Connect, Connect,
Response = (Connect, Io2, Protocol), Response = (Connect, Io2, Protocol),
Error = ConnectorError, Error = ConnectorError,
> + Clone, > + Clone,
@ -351,22 +348,21 @@ mod connect_impl {
} }
} }
impl<T1, T2, Io1, Io2> Service for InnerConnector<T1, T2, Io1, Io2> impl<T1, T2, Io1, Io2> Service<Connect> for InnerConnector<T1, T2, Io1, Io2>
where where
Io1: AsyncRead + AsyncWrite + 'static, Io1: AsyncRead + AsyncWrite + 'static,
Io2: AsyncRead + AsyncWrite + 'static, Io2: AsyncRead + AsyncWrite + 'static,
T1: Service< T1: Service<
Request = Connect, Connect,
Response = (Connect, Io1, Protocol), Response = (Connect, Io1, Protocol),
Error = ConnectorError, Error = ConnectorError,
>, >,
T2: Service< T2: Service<
Request = Connect, Connect,
Response = (Connect, Io2, Protocol), Response = (Connect, Io2, Protocol),
Error = ConnectorError, Error = ConnectorError,
>, >,
{ {
type Request = Connect;
type Response = EitherConnection<Io1, Io2>; type Response = EitherConnection<Io1, Io2>;
type Error = ConnectorError; type Error = ConnectorError;
type Future = Either< type Future = Either<
@ -401,23 +397,15 @@ 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< T: Service<Connect, Response = (Connect, Io1, Protocol), Error = ConnectorError>,
Request = Connect,
Response = (Connect, Io1, Protocol),
Error = ConnectorError,
>,
{ {
fut: <ConnectionPool<T, Io1> as Service>::Future, fut: <ConnectionPool<T, Io1> as Service<Connect>>::Future,
_t: PhantomData<Io2>, _t: PhantomData<Io2>,
} }
impl<T, Io1, Io2> Future for InnerConnectorResponseA<T, Io1, Io2> impl<T, Io1, Io2> Future for InnerConnectorResponseA<T, Io1, Io2>
where where
T: Service< T: Service<Connect, Response = (Connect, Io1, Protocol), Error = ConnectorError>,
Request = Connect,
Response = (Connect, Io1, Protocol),
Error = ConnectorError,
>,
Io1: AsyncRead + AsyncWrite + 'static, Io1: AsyncRead + AsyncWrite + 'static,
Io2: AsyncRead + AsyncWrite + 'static, Io2: AsyncRead + AsyncWrite + 'static,
{ {
@ -435,23 +423,15 @@ 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< T: Service<Connect, Response = (Connect, Io2, Protocol), Error = ConnectorError>,
Request = Connect,
Response = (Connect, Io2, Protocol),
Error = ConnectorError,
>,
{ {
fut: <ConnectionPool<T, Io2> as Service>::Future, fut: <ConnectionPool<T, Io2> as Service<Connect>>::Future,
_t: PhantomData<Io1>, _t: PhantomData<Io1>,
} }
impl<T, Io1, Io2> Future for InnerConnectorResponseB<T, Io1, Io2> impl<T, Io1, Io2> Future for InnerConnectorResponseB<T, Io1, Io2>
where where
T: Service< T: Service<Connect, Response = (Connect, Io2, Protocol), Error = ConnectorError>,
Request = Connect,
Response = (Connect, Io2, Protocol),
Error = ConnectorError,
>,
Io1: AsyncRead + AsyncWrite + 'static, Io1: AsyncRead + AsyncWrite + 'static,
Io2: AsyncRead + AsyncWrite + 'static, Io2: AsyncRead + AsyncWrite + 'static,
{ {

View File

@ -48,11 +48,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< T: Service<Connect, Response = (Connect, Io, Protocol), Error = ConnectorError>,
Request = Connect,
Response = (Connect, Io, Protocol),
Error = ConnectorError,
>,
{ {
pub(crate) fn new( pub(crate) fn new(
connector: T, connector: T,
@ -88,16 +84,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< T: Service<Connect, Response = (Connect, Io, Protocol), Error = ConnectorError>,
Request = Connect,
Response = (Connect, Io, Protocol),
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<

View File

@ -176,7 +176,7 @@ where
) -> impl Future<Item = ClientResponse, Error = SendRequestError> ) -> impl Future<Item = ClientResponse, Error = SendRequestError>
where where
B: 'static, B: 'static,
T: Service<Request = Connect, Response = I, Error = ConnectorError>, T: Service<Connect, Response = I, Error = ConnectorError>,
I: Connection, I: Connection,
{ {
let Self { head, body } = self; let Self { head, body } = self;

View File

@ -36,14 +36,14 @@ bitflags! {
} }
/// Dispatcher for HTTP/1.1 protocol /// Dispatcher for HTTP/1.1 protocol
pub struct Dispatcher<T, S: Service + 'static, B: MessageBody> pub struct Dispatcher<T, S: Service<Request> + 'static, 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 + 'static, B: MessageBody> struct InnerDispatcher<T, S: Service<Request> + 'static, 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> + 'static, S: Service<Request> + 'static,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
@ -141,7 +141,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> + 'static, S: Service<Request> + 'static,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
@ -464,7 +464,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>, S: Service<Request>,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,

View File

@ -28,14 +28,14 @@ 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>, S: NewService<Request>,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
S::Service: 'static, S::Service: 'static,
B: MessageBody, B: MessageBody,
{ {
/// Create new `HttpService` instance with default config. /// Create new `HttpService` instance with default config.
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 {
@ -46,7 +46,10 @@ where
} }
/// Create new `HttpService` instance with config. /// Create new `HttpService` instance with config.
pub fn with_config<F: IntoNewService<S>>(cfg: ServiceConfig, service: F) -> Self { pub fn with_config<F: IntoNewService<S, Request>>(
cfg: ServiceConfig,
service: F,
) -> Self {
H1Service { H1Service {
cfg, cfg,
srv: service.into_new_service(), srv: service.into_new_service(),
@ -60,16 +63,15 @@ 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>, S: NewService<Request>,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
S::Service: 'static, S::Service: 'static,
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;
@ -101,7 +103,7 @@ pub struct H1ServiceBuilder<T, S> {
impl<T, S> H1ServiceBuilder<T, S> impl<T, S> H1ServiceBuilder<T, S>
where where
S: NewService<Request = Request>, S: NewService<Request>,
S::Error: Debug, S::Error: Debug,
{ {
/// Create instance of `ServiceConfigBuilder` /// Create instance of `ServiceConfigBuilder`
@ -199,7 +201,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,
@ -215,7 +217,7 @@ where
} }
#[doc(hidden)] #[doc(hidden)]
pub struct H1ServiceResponse<T, S: NewService, B> { pub struct H1ServiceResponse<T, S: NewService<Request>, B> {
fut: <S::Future as IntoFuture>::Future, fut: <S::Future as IntoFuture>::Future,
cfg: Option<ServiceConfig>, cfg: Option<ServiceConfig>,
_t: PhantomData<(T, B)>, _t: PhantomData<(T, B)>,
@ -224,7 +226,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>, S: NewService<Request>,
S::Service: 'static, S::Service: 'static,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
@ -251,7 +253,7 @@ pub struct H1ServiceHandler<T, S: 'static, B> {
impl<T, S, B> H1ServiceHandler<T, S, B> impl<T, S, B> H1ServiceHandler<T, S, B>
where where
S: Service<Request = Request>, S: Service<Request>,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
@ -265,15 +267,14 @@ 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>, S: Service<Request>,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
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>;
@ -307,11 +308,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 = ();
@ -333,11 +333,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>;

View File

@ -38,7 +38,11 @@ bitflags! {
} }
/// Dispatcher for HTTP/2 protocol /// Dispatcher for HTTP/2 protocol
pub struct Dispatcher<T: AsyncRead + AsyncWrite, S: Service + 'static, B: MessageBody> { pub struct Dispatcher<
T: AsyncRead + AsyncWrite,
S: Service<Request<Payload>> + 'static,
B: MessageBody,
> {
flags: Flags, flags: Flags,
service: CloneableService<S>, service: CloneableService<S>,
connection: Connection<T, Bytes>, connection: Connection<T, Bytes>,
@ -51,7 +55,7 @@ pub struct Dispatcher<T: AsyncRead + AsyncWrite, S: Service + 'static, B: Messag
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<Payload>> + 'static, S: Service<Request<Payload>> + 'static,
S::Error: Into<Error> + fmt::Debug, S::Error: Into<Error> + fmt::Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
@ -93,7 +97,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<Payload>> + 'static, S: Service<Request<Payload>> + 'static,
S::Error: Into<Error> + fmt::Debug, S::Error: Into<Error> + fmt::Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
@ -139,20 +143,20 @@ where
} }
} }
struct ServiceResponse<S: Service, B> { struct ServiceResponse<S: Service<Request<Payload>>, B> {
state: ServiceResponseState<S, B>, state: ServiceResponseState<S, B>,
config: ServiceConfig, config: ServiceConfig,
buffer: Option<Bytes>, buffer: Option<Bytes>,
} }
enum ServiceResponseState<S: Service, B> { enum ServiceResponseState<S: Service<Request<Payload>>, B> {
ServiceCall(S::Future, Option<SendResponse<Bytes>>), ServiceCall(S::Future, Option<SendResponse<Bytes>>),
SendPayload(SendStream<Bytes>, ResponseBody<B>), SendPayload(SendStream<Bytes>, ResponseBody<B>),
} }
impl<S, B> ServiceResponse<S, B> impl<S, B> ServiceResponse<S, B>
where where
S: Service<Request = Request<Payload>> + 'static, S: Service<Request<Payload>> + 'static,
S::Error: Into<Error> + fmt::Debug, S::Error: Into<Error> + fmt::Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
@ -220,7 +224,7 @@ where
impl<S, B> Future for ServiceResponse<S, B> impl<S, B> Future for ServiceResponse<S, B>
where where
S: Service<Request = Request<Payload>> + 'static, S: Service<Request<Payload>> + 'static,
S::Error: Into<Error> + fmt::Debug, S::Error: Into<Error> + fmt::Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,

View File

@ -31,14 +31,14 @@ pub struct H2Service<T, S, B> {
impl<T, S, B> H2Service<T, S, B> impl<T, S, B> H2Service<T, S, B>
where where
S: NewService<Request = Request<Payload>>, S: NewService<Request<Payload>>,
S::Service: 'static, S::Service: 'static,
S::Error: Into<Error> + Debug + 'static, S::Error: Into<Error> + Debug + 'static,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
/// Create new `HttpService` instance. /// Create new `HttpService` instance.
pub fn new<F: IntoNewService<S>>(service: F) -> Self { pub fn new<F: IntoNewService<S, Request<Payload>>>(service: F) -> Self {
let cfg = ServiceConfig::new(KeepAlive::Timeout(5), 5000, 0); let cfg = ServiceConfig::new(KeepAlive::Timeout(5), 5000, 0);
H2Service { H2Service {
@ -54,16 +54,15 @@ where
} }
} }
impl<T, S, B> NewService for H2Service<T, S, B> impl<T, S, B> NewService<T> for H2Service<T, S, B>
where where
T: AsyncRead + AsyncWrite, T: AsyncRead + AsyncWrite,
S: NewService<Request = Request<Payload>>, S: NewService<Request<Payload>>,
S::Service: 'static, S::Service: 'static,
S::Error: Into<Error> + Debug, S::Error: Into<Error> + Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
type Request = T;
type Response = (); type Response = ();
type Error = DispatchError<()>; type Error = DispatchError<()>;
type InitError = S::InitError; type InitError = S::InitError;
@ -95,7 +94,7 @@ pub struct H2ServiceBuilder<T, S> {
impl<T, S> H2ServiceBuilder<T, S> impl<T, S> H2ServiceBuilder<T, S>
where where
S: NewService<Request = Request<Payload>>, S: NewService<Request<Payload>>,
S::Service: 'static, S::Service: 'static,
S::Error: Into<Error> + Debug + 'static, S::Error: Into<Error> + Debug + 'static,
{ {
@ -213,7 +212,7 @@ where
pub fn finish<F, B>(self, service: F) -> H2Service<T, S, B> pub fn finish<F, B>(self, service: F) -> H2Service<T, S, B>
where where
B: MessageBody, B: MessageBody,
F: IntoNewService<S>, F: IntoNewService<S, Request<Payload>>,
{ {
let cfg = ServiceConfig::new( let cfg = ServiceConfig::new(
self.keep_alive, self.keep_alive,
@ -229,7 +228,7 @@ where
} }
#[doc(hidden)] #[doc(hidden)]
pub struct H2ServiceResponse<T, S: NewService, B> { pub struct H2ServiceResponse<T, S: NewService<Request<Payload>>, B> {
fut: <S::Future as IntoFuture>::Future, fut: <S::Future as IntoFuture>::Future,
cfg: Option<ServiceConfig>, cfg: Option<ServiceConfig>,
_t: PhantomData<(T, B)>, _t: PhantomData<(T, B)>,
@ -238,7 +237,7 @@ pub struct H2ServiceResponse<T, S: NewService, B> {
impl<T, S, B> Future for H2ServiceResponse<T, S, B> impl<T, S, B> Future for H2ServiceResponse<T, S, B>
where where
T: AsyncRead + AsyncWrite, T: AsyncRead + AsyncWrite,
S: NewService<Request = Request<Payload>>, S: NewService<Request<Payload>>,
S::Service: 'static, S::Service: 'static,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
S::Error: Into<Error> + Debug, S::Error: Into<Error> + Debug,
@ -265,7 +264,7 @@ pub struct H2ServiceHandler<T, S: 'static, B> {
impl<T, S, B> H2ServiceHandler<T, S, B> impl<T, S, B> H2ServiceHandler<T, S, B>
where where
S: Service<Request = Request<Payload>> + 'static, S: Service<Request<Payload>> + 'static,
S::Error: Into<Error> + Debug, S::Error: Into<Error> + Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
@ -279,15 +278,14 @@ where
} }
} }
impl<T, S, B> Service for H2ServiceHandler<T, S, B> impl<T, S, B> Service<T> for H2ServiceHandler<T, S, B>
where where
T: AsyncRead + AsyncWrite, T: AsyncRead + AsyncWrite,
S: Service<Request = Request<Payload>> + 'static, S: Service<Request<Payload>> + 'static,
S::Error: Into<Error> + Debug, S::Error: Into<Error> + Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
type Request = T;
type Response = (); type Response = ();
type Error = DispatchError<()>; type Error = DispatchError<()>;
type Future = H2ServiceHandlerResponse<T, S, B>; type Future = H2ServiceHandlerResponse<T, S, B>;
@ -310,7 +308,11 @@ where
} }
} }
enum State<T: AsyncRead + AsyncWrite, S: Service + 'static, B: MessageBody> { enum State<
T: AsyncRead + AsyncWrite,
S: Service<Request<Payload>> + 'static,
B: MessageBody,
> {
Incoming(Dispatcher<T, S, B>), Incoming(Dispatcher<T, S, B>),
Handshake( Handshake(
Option<CloneableService<S>>, Option<CloneableService<S>>,
@ -322,7 +324,7 @@ enum State<T: AsyncRead + AsyncWrite, S: Service + 'static, B: MessageBody> {
pub struct H2ServiceHandlerResponse<T, S, B> pub struct H2ServiceHandlerResponse<T, S, B>
where where
T: AsyncRead + AsyncWrite, T: AsyncRead + AsyncWrite,
S: Service<Request = Request<Payload>> + 'static, S: Service<Request<Payload>> + 'static,
S::Error: Into<Error> + Debug, S::Error: Into<Error> + Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
@ -333,7 +335,7 @@ where
impl<T, S, B> Future for H2ServiceHandlerResponse<T, S, B> impl<T, S, B> Future for H2ServiceHandlerResponse<T, S, B>
where where
T: AsyncRead + AsyncWrite, T: AsyncRead + AsyncWrite,
S: Service<Request = Request<Payload>> + 'static, S: Service<Request<Payload>> + 'static,
S::Error: Into<Error> + Debug, S::Error: Into<Error> + Debug,
S::Response: Into<Response<B>>, S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,

View File

@ -22,12 +22,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 = ();
@ -39,12 +38,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>>;
@ -130,12 +128,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 = ();
@ -147,12 +144,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>;

View File

@ -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<Request = TcpConnect, 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<

View File

@ -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>;

View File

@ -7,7 +7,7 @@ use super::{Codec, Frame, Message};
pub struct Transport<S, T> pub struct Transport<S, T>
where where
S: Service<Request = Frame, Response = Message> + 'static, S: Service<Frame, Response = Message> + 'static,
T: AsyncRead + AsyncWrite, T: AsyncRead + AsyncWrite,
{ {
inner: FramedTransport<S, T, Codec>, inner: FramedTransport<S, T, Codec>,
@ -16,17 +16,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),
} }
@ -36,7 +36,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,
{ {

View File

@ -35,10 +35,12 @@ ssl = ["openssl", "actix-http/ssl", "actix-server/ssl"]
actix-codec = "0.1" actix-codec = "0.1"
actix-rt = "0.1.0" actix-rt = "0.1.0"
actix-http = { path=".." } actix-http = { path=".." }
actix-service = "0.3.2" #actix-service = "0.3.2"
actix-service = { git="https://github.com/actix/actix-net.git" }
#actix-server = "0.3.0" #actix-server = "0.3.0"
actix-server = { git="https://github.com/actix/actix-net.git" } actix-server = { git="https://github.com/actix/actix-net.git" }
actix-utils = "0.3.2" #actix-utils = "0.3.2"
actix-utils = { git="https://github.com/actix/actix-net.git" }
base64 = "0.10" base64 = "0.10"
bytes = "0.4" bytes = "0.4"

View File

@ -56,8 +56,7 @@ impl TestServer {
pub fn new<F: StreamServiceFactory>( pub fn new<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();
@ -89,11 +88,8 @@ impl TestServer {
} }
fn new_connector( fn new_connector(
) -> impl Service< ) -> impl Service<Connect, Response = impl Connection, Error = ConnectorError> + Clone
Request = Connect, {
Response = impl Connection,
Error = ConnectorError,
> + Clone {
#[cfg(feature = "ssl")] #[cfg(feature = "ssl")]
{ {
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode}; use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
@ -206,7 +202,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