extern crate actix_web; use actix_web::middleware::{Finished, Middleware, Response, Started}; use actix_web::{HttpRequest, HttpResponse, Result}; // Middleware can get called at three stages during the request/response handling. Below is a // struct that implements all three of them. pub struct SayHi; impl Middleware for SayHi { fn start(&self, req: &mut HttpRequest) -> Result { println!("Hi from start. You requested: {}", req.path()); Ok(Started::Done) } fn response( &self, _req: &mut HttpRequest, resp: HttpResponse, ) -> Result { println!("Hi from response"); Ok(Response::Done(resp)) } fn finish(&self, _req: &mut HttpRequest, _resp: &HttpResponse) -> Finished { println!("Hi from finish"); Finished::Done } }