mirror of https://github.com/fafhrd91/actix-web
add noop middleware for testing
This commit is contained in:
parent
3f6d853d2f
commit
b71ca411ab
|
@ -5,6 +5,8 @@ mod condition;
|
||||||
mod default_headers;
|
mod default_headers;
|
||||||
mod err_handlers;
|
mod err_handlers;
|
||||||
mod logger;
|
mod logger;
|
||||||
|
#[cfg(test)]
|
||||||
|
mod noop;
|
||||||
mod normalize;
|
mod normalize;
|
||||||
|
|
||||||
pub use self::compat::Compat;
|
pub use self::compat::Compat;
|
||||||
|
@ -12,6 +14,8 @@ pub use self::condition::Condition;
|
||||||
pub use self::default_headers::DefaultHeaders;
|
pub use self::default_headers::DefaultHeaders;
|
||||||
pub use self::err_handlers::{ErrorHandlerResponse, ErrorHandlers};
|
pub use self::err_handlers::{ErrorHandlerResponse, ErrorHandlers};
|
||||||
pub use self::logger::Logger;
|
pub use self::logger::Logger;
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) use self::noop::Noop;
|
||||||
pub use self::normalize::{NormalizePath, TrailingSlash};
|
pub use self::normalize::{NormalizePath, TrailingSlash};
|
||||||
|
|
||||||
#[cfg(feature = "__compress")]
|
#[cfg(feature = "__compress")]
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
//! A no-op middleware. See [Noop] for docs.
|
||||||
|
|
||||||
|
use actix_utils::future::{ready, Ready};
|
||||||
|
|
||||||
|
use crate::dev::{Service, Transform};
|
||||||
|
|
||||||
|
/// A no-op middleware that passes through request and response untouched.
|
||||||
|
pub(crate) struct Noop;
|
||||||
|
|
||||||
|
impl<S: Service<Req>, Req> Transform<S, Req> for Noop {
|
||||||
|
type Response = S::Response;
|
||||||
|
type Error = S::Error;
|
||||||
|
type Transform = NoopService<S>;
|
||||||
|
type InitError = ();
|
||||||
|
type Future = Ready<Result<Self::Transform, Self::InitError>>;
|
||||||
|
|
||||||
|
fn new_transform(&self, service: S) -> Self::Future {
|
||||||
|
ready(Ok(NoopService { service }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub(crate) struct NoopService<S> {
|
||||||
|
service: S,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: Service<Req>, Req> Service<Req> for NoopService<S> {
|
||||||
|
type Response = S::Response;
|
||||||
|
type Error = S::Error;
|
||||||
|
type Future = S::Future;
|
||||||
|
|
||||||
|
crate::dev::forward_ready!(service);
|
||||||
|
|
||||||
|
fn call(&self, req: Req) -> Self::Future {
|
||||||
|
self.service.call(req)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue