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

Change service response to Into<Response>

This commit is contained in:
Nikolay Kim 2019-02-09 08:44:22 -08:00
parent ed7ca7fe07
commit f3ed1b601e
4 changed files with 41 additions and 22 deletions

View File

@ -85,8 +85,9 @@ 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 = Request>,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
{ {
/// Create http/1 dispatcher. /// Create http/1 dispatcher.
@ -139,8 +140,9 @@ 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 = Request>,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
{ {
fn can_read(&self) -> bool { fn can_read(&self) -> bool {
@ -224,7 +226,7 @@ where
State::ServiceCall(mut fut) => { State::ServiceCall(mut fut) => {
match fut.poll().map_err(DispatchError::Service)? { match fut.poll().map_err(DispatchError::Service)? {
Async::Ready(res) => { Async::Ready(res) => {
let (res, body) = res.replace_body(()); let (res, body) = res.into().replace_body(());
Some(self.send_response(res, body)?) Some(self.send_response(res, body)?)
} }
Async::NotReady => { Async::NotReady => {
@ -287,7 +289,7 @@ where
let mut task = self.service.call(req); let mut task = self.service.call(req);
match task.poll().map_err(DispatchError::Service)? { match task.poll().map_err(DispatchError::Service)? {
Async::Ready(res) => { Async::Ready(res) => {
let (res, body) = res.replace_body(()); let (res, body) = res.into().replace_body(());
self.send_response(res, body) self.send_response(res, body)
} }
Async::NotReady => Ok(State::ServiceCall(task)), Async::NotReady => Ok(State::ServiceCall(task)),
@ -459,8 +461,9 @@ 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 = Request>,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
{ {
type Item = H1ServiceResult<T>; type Item = H1ServiceResult<T>;

View File

@ -28,9 +28,10 @@ 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<Payload>, Response = Response<B>> + Clone, S: NewService<Request = Request<Payload>> + Clone,
S::Service: Clone, S::Service: Clone,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
{ {
/// Create new `HttpService` instance. /// Create new `HttpService` instance.
@ -53,9 +54,10 @@ where
impl<T, S, B> NewService for H1Service<T, S, B> impl<T, S, B> NewService for H1Service<T, S, B>
where where
T: AsyncRead + AsyncWrite, T: AsyncRead + AsyncWrite,
S: NewService<Request = Request, Response = Response<B>> + Clone, S: NewService<Request = Request> + Clone,
S::Service: Clone, S::Service: Clone,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
{ {
type Request = T; type Request = T;
@ -214,9 +216,10 @@ 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 = Request>,
S::Service: Clone, S::Service: Clone,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
{ {
type Item = H1ServiceHandler<T, S::Service, B>; type Item = H1ServiceHandler<T, S::Service, B>;
@ -240,8 +243,9 @@ 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 = Request> + Clone,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
{ {
fn new(cfg: ServiceConfig, srv: S) -> H1ServiceHandler<T, S, B> { fn new(cfg: ServiceConfig, srv: S) -> H1ServiceHandler<T, S, B> {
@ -256,8 +260,9 @@ where
impl<T, S, B> Service for H1ServiceHandler<T, S, B> impl<T, S, B> Service for H1ServiceHandler<T, S, B>
where where
T: AsyncRead + AsyncWrite, T: AsyncRead + AsyncWrite,
S: Service<Request = Request, Response = Response<B>> + Clone, S: Service<Request = Request> + Clone,
S::Error: Debug, S::Error: Debug,
S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
{ {
type Request = T; type Request = T;

View File

@ -50,8 +50,9 @@ pub struct Dispatcher<T: AsyncRead + AsyncWrite, S: Service, B: MessageBody> {
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>, Response = Response<B>> + 'static, S: Service<Request = Request<Payload>> + 'static,
S::Error: Into<Error> + fmt::Debug, S::Error: Into<Error> + fmt::Debug,
S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
pub fn new( pub fn new(
@ -91,8 +92,9 @@ 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>, Response = Response<B>> + 'static, S: Service<Request = Request<Payload>> + 'static,
S::Error: Into<Error> + fmt::Debug, S::Error: Into<Error> + fmt::Debug,
S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
type Item = (); type Item = ();
@ -149,8 +151,9 @@ enum ServiceResponseState<S: Service, B> {
impl<S, B> ServiceResponse<S, B> impl<S, B> ServiceResponse<S, B>
where where
S: Service<Request = Request<Payload>, Response = Response<B>> + 'static, S: Service<Request = Request<Payload>> + 'static,
S::Error: Into<Error> + fmt::Debug, S::Error: Into<Error> + fmt::Debug,
S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
fn prepare_response( fn prepare_response(
@ -216,8 +219,9 @@ where
impl<S, B> Future for ServiceResponse<S, B> impl<S, B> Future for ServiceResponse<S, B>
where where
S: Service<Request = Request<Payload>, Response = Response<B>> + 'static, S: Service<Request = Request<Payload>> + 'static,
S::Error: Into<Error> + fmt::Debug, S::Error: Into<Error> + fmt::Debug,
S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
type Item = (); type Item = ();
@ -228,7 +232,7 @@ where
ServiceResponseState::ServiceCall(ref mut call, ref mut send) => { ServiceResponseState::ServiceCall(ref mut call, ref mut send) => {
match call.poll() { match call.poll() {
Ok(Async::Ready(res)) => { Ok(Async::Ready(res)) => {
let (res, body) = res.replace_body(()); let (res, body) = res.into().replace_body(());
let mut send = send.take().unwrap(); let mut send = send.take().unwrap();
let mut length = body.length(); let mut length = body.length();

View File

@ -30,9 +30,10 @@ 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>, Response = Response<B>> + Clone, S: NewService<Request = Request<Payload>> + Clone,
S::Service: Clone + 'static, S::Service: Clone + 'static,
S::Error: Into<Error> + Debug + 'static, S::Error: Into<Error> + Debug + 'static,
S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
/// Create new `HttpService` instance. /// Create new `HttpService` instance.
@ -55,9 +56,10 @@ where
impl<T, S, B> NewService for H2Service<T, S, B> impl<T, S, B> NewService for H2Service<T, S, B>
where where
T: AsyncRead + AsyncWrite, T: AsyncRead + AsyncWrite,
S: NewService<Request = Request<Payload>, Response = Response<B>> + Clone, S: NewService<Request = Request<Payload>> + Clone,
S::Service: Clone + 'static, S::Service: Clone + 'static,
S::Error: Into<Error> + Debug, S::Error: Into<Error> + Debug,
S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
type Request = T; type Request = T;
@ -235,8 +237,9 @@ 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>, Response = Response<B>>, S: NewService<Request = Request<Payload>>,
S::Service: Clone + 'static, S::Service: Clone + 'static,
S::Response: Into<Response<B>>,
S::Error: Into<Error> + Debug, S::Error: Into<Error> + Debug,
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
@ -261,8 +264,9 @@ pub struct H2ServiceHandler<T, S, B> {
impl<T, S, B> H2ServiceHandler<T, S, B> impl<T, S, B> H2ServiceHandler<T, S, B>
where where
S: Service<Request = Request<Payload>, Response = Response<B>> + Clone + 'static, S: Service<Request = Request<Payload>> + Clone + 'static,
S::Error: Into<Error> + Debug, S::Error: Into<Error> + Debug,
S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
fn new(cfg: ServiceConfig, srv: S) -> H2ServiceHandler<T, S, B> { fn new(cfg: ServiceConfig, srv: S) -> H2ServiceHandler<T, S, B> {
@ -277,8 +281,9 @@ where
impl<T, S, B> Service for H2ServiceHandler<T, S, B> impl<T, S, B> Service for H2ServiceHandler<T, S, B>
where where
T: AsyncRead + AsyncWrite, T: AsyncRead + AsyncWrite,
S: Service<Request = Request<Payload>, Response = Response<B>> + Clone + 'static, S: Service<Request = Request<Payload>> + Clone + 'static,
S::Error: Into<Error> + Debug, S::Error: Into<Error> + Debug,
S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
type Request = T; type Request = T;
@ -312,8 +317,9 @@ enum State<T: AsyncRead + AsyncWrite, S: Service, 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>, Response = Response<B>> + Clone + 'static, S: Service<Request = Request<Payload>> + Clone + 'static,
S::Error: Into<Error> + Debug, S::Error: Into<Error> + Debug,
S::Response: Into<Response<B>>,
B: MessageBody + 'static, B: MessageBody + 'static,
{ {
state: State<T, S, B>, state: State<T, S, B>,
@ -322,8 +328,9 @@ 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>, Response = Response<B>> + Clone, S: Service<Request = Request<Payload>> + Clone,
S::Error: Into<Error> + Debug, S::Error: Into<Error> + Debug,
S::Response: Into<Response<B>>,
B: MessageBody, B: MessageBody,
{ {
type Item = (); type Item = ();