1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-13 02:39:32 +00:00
actix-web/src/middleware/mod.rs
2019-03-01 22:51:32 -08:00

66 lines
1.3 KiB
Rust

use std::marker::PhantomData;
use actix_service::{NewTransform, Service, Transform};
use futures::future::{ok, FutureResult};
#[cfg(any(feature = "brotli", feature = "flate2"))]
mod compress;
#[cfg(any(feature = "brotli", feature = "flate2"))]
pub use self::compress::Compress;
mod defaultheaders;
pub use self::defaultheaders::DefaultHeaders;
/// Helper for middleware service factory
pub struct MiddlewareFactory<T, S>
where
T: Transform<S> + Clone,
S: Service,
{
tr: T,
_t: PhantomData<S>,
}
impl<T, S> MiddlewareFactory<T, S>
where
T: Transform<S> + Clone,
S: Service,
{
pub fn new(tr: T) -> Self {
MiddlewareFactory {
tr,
_t: PhantomData,
}
}
}
impl<T, S> Clone for MiddlewareFactory<T, S>
where
T: Transform<S> + Clone,
S: Service,
{
fn clone(&self) -> Self {
Self {
tr: self.tr.clone(),
_t: PhantomData,
}
}
}
impl<T, S> NewTransform<S> for MiddlewareFactory<T, S>
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>;
fn new_transform(&self) -> Self::Future {
ok(self.tr.clone())
}
}