diff --git a/src/server/h2service.rs b/src/server/h2service.rs index 4535f39b..52e41c3e 100644 --- a/src/server/h2service.rs +++ b/src/server/h2service.rs @@ -2,6 +2,7 @@ use failure::*; use std::collections::HashMap; use std::sync::Arc; +use std::task::{Context, Poll}; use futures::*; use hyper::{Body, Request, Response, StatusCode}; @@ -83,19 +84,23 @@ impl H2Service { } } -impl hyper::service::Service for H2Service { - type ReqBody = Body; - type ResBody = Body; +impl tower_service::Service> for H2Service { + type Response = Response; type Error = Error; - type Future = Box, Error = Self::Error> + Send>; + type Future = + std::pin::Pin, Self::Error>> + Send>>; - fn call(&mut self, req: Request) -> Self::Future { + fn poll_ready(&mut self, _cx: &mut Context) -> Poll> { + Poll::Ready(Ok(())) + } + + fn call(&mut self, req: Request) -> Self::Future { let path = req.uri().path().to_owned(); let method = req.method().clone(); let worker = self.worker.clone(); - Box::new(self.handle_request(req).then(move |result| { - match result { + std::pin::Pin::from(self.handle_request(req)) + .map(move |result| match result { Ok(res) => { Self::log_response(worker, method, &path, &res); Ok::<_, Error>(res) @@ -115,7 +120,7 @@ impl hyper::service::Service for H2Service { Ok(resp) } } - } - })) + }) + .boxed() } }