-
Notifications
You must be signed in to change notification settings - Fork 51
/
middleware.rs
33 lines (28 loc) · 903 Bytes
/
middleware.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use super::LogService;
use crate::middleware::Middleware;
use http;
use tower_service::Service;
/// Decorate a service by logging all received requests.
#[derive(Debug)]
pub struct LogMiddleware {
target: &'static str,
}
impl LogMiddleware {
/// Create a new `LogMiddleware` instance configured to use `target`.
pub fn new(target: &'static str) -> LogMiddleware {
LogMiddleware { target }
}
}
impl<S, RequestBody, ResponseBody> Middleware<S> for LogMiddleware
where S: Service<Request = http::Request<RequestBody>,
Response = http::Response<ResponseBody>>,
S::Error: ::std::error::Error,
{
type Request = http::Request<RequestBody>;
type Response = http::Response<ResponseBody>;
type Error = S::Error;
type Service = LogService<S>;
fn wrap(&self, service: S) -> Self::Service {
LogService::new(service, self.target)
}
}