2019-03-02 06:51:32 +00:00
|
|
|
use std::marker::PhantomData;
|
2017-11-25 06:15:52 +00:00
|
|
|
|
2019-03-02 06:51:32 +00:00
|
|
|
use actix_service::{NewTransform, Service, Transform};
|
|
|
|
use futures::future::{ok, FutureResult};
|
2017-11-10 06:08:54 +00:00
|
|
|
|
2019-03-02 06:51:32 +00:00
|
|
|
#[cfg(any(feature = "brotli", feature = "flate2"))]
|
|
|
|
mod compress;
|
|
|
|
#[cfg(any(feature = "brotli", feature = "flate2"))]
|
|
|
|
pub use self::compress::Compress;
|
2018-03-07 07:38:58 +00:00
|
|
|
|
2018-04-13 23:02:01 +00:00
|
|
|
mod defaultheaders;
|
2018-04-03 04:43:50 +00:00
|
|
|
pub use self::defaultheaders::DefaultHeaders;
|
2018-03-07 07:38:58 +00:00
|
|
|
|
2019-03-02 06:51:32 +00:00
|
|
|
/// Helper for middleware service factory
|
|
|
|
pub struct MiddlewareFactory<T, S>
|
|
|
|
where
|
|
|
|
T: Transform<S> + Clone,
|
|
|
|
S: Service,
|
|
|
|
{
|
|
|
|
tr: T,
|
|
|
|
_t: PhantomData<S>,
|
2017-11-10 06:08:54 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 06:51:32 +00:00
|
|
|
impl<T, S> MiddlewareFactory<T, S>
|
|
|
|
where
|
|
|
|
T: Transform<S> + Clone,
|
|
|
|
S: Service,
|
|
|
|
{
|
|
|
|
pub fn new(tr: T) -> Self {
|
|
|
|
MiddlewareFactory {
|
|
|
|
tr,
|
|
|
|
_t: PhantomData,
|
|
|
|
}
|
|
|
|
}
|
2017-11-10 06:08:54 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 21:57:00 +00:00
|
|
|
impl<T, S, C> NewTransform<S, C> for MiddlewareFactory<T, S>
|
2019-03-02 06:51:32 +00:00
|
|
|
where
|
|
|
|
T: Transform<S> + Clone,
|
|
|
|
S: Service,
|
|
|
|
{
|
|
|
|
type Request = T::Request;
|
|
|
|
type Response = T::Response;
|
|
|
|
type Error = T::Error;
|
|
|
|
type Transform = T;
|
|
|
|
type InitError = ();
|
|
|
|
type Future = FutureResult<Self::Transform, Self::InitError>;
|
2017-11-10 06:08:54 +00:00
|
|
|
|
2019-03-02 21:57:00 +00:00
|
|
|
fn new_transform(&self, _: &C) -> Self::Future {
|
2019-03-02 06:51:32 +00:00
|
|
|
ok(self.tr.clone())
|
2017-11-10 06:08:54 +00:00
|
|
|
}
|
|
|
|
}
|