use crate::service::{Layer, Service};
use crate::{BaseBody, ResponseBody};
use http::Response;
pub struct ResponseBodyLayer;
impl<S> Layer<S> for ResponseBodyLayer {
type Service = ResponseBodyService<S>;
fn layer(self, inner: S) -> Self::Service {
ResponseBodyService { inner }
}
}
pub struct ResponseBodyService<S> {
inner: S,
}
impl<S, R> Service<R> for ResponseBodyService<S>
where
S: Service<R, Response = Response<BaseBody>>,
{
type Response = Response<ResponseBody>;
type Error = S::Error;
async fn call(&self, req: R) -> Result<Self::Response, Self::Error> {
self.inner.call(req).await.map(|r| r.map(ResponseBody::new))
}
}