mirror of
https://github.com/fafhrd91/actix-web
synced 2025-07-01 08:45:10 +02:00
add middleware composition tests (#2375)
This commit is contained in:
@ -19,3 +19,43 @@ mod compress;
|
||||
|
||||
#[cfg(feature = "__compress")]
|
||||
pub use self::compress::Compress;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{http::StatusCode, App};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn common_combinations() {
|
||||
// ensure there's no reason that the built-in middleware cannot compose
|
||||
|
||||
let _ = App::new()
|
||||
.wrap(Compat::new(Logger::default()))
|
||||
.wrap(Condition::new(true, DefaultHeaders::new()))
|
||||
.wrap(DefaultHeaders::new().header("X-Test2", "X-Value2"))
|
||||
.wrap(ErrorHandlers::new().handler(StatusCode::FORBIDDEN, |res| {
|
||||
Ok(ErrorHandlerResponse::Response(res))
|
||||
}))
|
||||
.wrap(Logger::default())
|
||||
.wrap(NormalizePath::new(TrailingSlash::Trim));
|
||||
|
||||
let _ = App::new()
|
||||
.wrap(NormalizePath::new(TrailingSlash::Trim))
|
||||
.wrap(Logger::default())
|
||||
.wrap(ErrorHandlers::new().handler(StatusCode::FORBIDDEN, |res| {
|
||||
Ok(ErrorHandlerResponse::Response(res))
|
||||
}))
|
||||
.wrap(DefaultHeaders::new().header("X-Test2", "X-Value2"))
|
||||
.wrap(Condition::new(true, DefaultHeaders::new()))
|
||||
.wrap(Compat::new(Logger::default()));
|
||||
|
||||
#[cfg(feature = "__compress")]
|
||||
{
|
||||
let _ = App::new().wrap(Compress::default()).wrap(Logger::default());
|
||||
let _ = App::new().wrap(Logger::default()).wrap(Compress::default());
|
||||
let _ = App::new().wrap(Compat::new(Compress::default()));
|
||||
let _ = App::new().wrap(Condition::new(true, Compat::new(Compress::default())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user