From 948054f1e4d581c6f2122ef984d9b6be308c264c Mon Sep 17 00:00:00 2001 From: Sven-Hendrik Haase Date: Wed, 11 Sep 2019 14:04:33 +0200 Subject: [PATCH] Add middleware example with wrap_fn --- middleware/src/main.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/middleware/src/main.rs b/middleware/src/main.rs index 0496db27..647d710e 100644 --- a/middleware/src/main.rs +++ b/middleware/src/main.rs @@ -1,4 +1,6 @@ use actix_web::{web, App, HttpServer}; +use actix_service::Service; +use futures::future::Future; #[allow(dead_code)] mod redirect; @@ -13,6 +15,14 @@ fn main() -> std::io::Result<()> { App::new() .wrap(redirect::CheckLogin) .wrap(simple::SayHi) + .wrap_fn(|req, srv| { + println!("Hi from start. You requested: {}", req.path()); + + srv.call(req).map(|res| { + println!("Hi from response"); + res + }) + }) .service(web::resource("/login").to(|| { "You are on /login. Go to src/redirect.rs to change this behavior." }))