1use error::Catch;
2use routing::{Resource, RoutedService};
3use util::http::{HttpMiddleware, HttpService};
4
5use futures::Poll;
6use http;
7use tower_service::Service;
8
9use std::fmt;
10
11pub struct WebService<T, U, M>
17where
18 T: Resource,
19 U: Catch,
20 M: HttpMiddleware<RoutedService<T, U>>,
21{
22 inner: M::Service,
24}
25
26impl<T, U, M> WebService<T, U, M>
27where
28 T: Resource,
29 U: Catch,
30 M: HttpMiddleware<RoutedService<T, U>>,
31{
32 pub(crate) fn new(inner: M::Service) -> WebService<T, U, M> {
33 WebService { inner }
34 }
35}
36
37impl<T, U, M> Service for WebService<T, U, M>
38where
39 T: Resource,
40 U: Catch,
41 M: HttpMiddleware<RoutedService<T, U>>,
42{
43 type Request = http::Request<M::RequestBody>;
44 type Response = http::Response<M::ResponseBody>;
45 type Error = M::Error;
46 type Future = <M::Service as HttpService>::Future;
47
48 fn poll_ready(&mut self) -> Poll<(), Self::Error> {
49 self.inner.poll_http_ready()
50 }
51
52 fn call(&mut self, request: Self::Request) -> Self::Future {
53 self.inner.call_http(request)
54 }
55}
56
57impl<T, U, M> fmt::Debug for WebService<T, U, M>
58where T: Resource + fmt::Debug,
59 U: Catch + fmt::Debug,
60 M: HttpMiddleware<RoutedService<T, U>> + fmt::Debug,
61 M::Service: fmt::Debug,
62 M::RequestBody: fmt::Debug,
63 M::ResponseBody: fmt::Debug,
64 M::Error: fmt::Debug,
65{
66 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
67 fmt.debug_struct("WebService")
68 .field("inner", &self.inner)
69 .finish()
70 }
71}