mirror of
https://github.com/actix/examples
synced 2024-12-03 18:22:14 +01:00
26 lines
815 B
Rust
26 lines
815 B
Rust
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<S> Middleware<S> for SayHi {
|
|
fn start(&self, req: &HttpRequest<S>) -> Result<Started> {
|
|
println!("Hi from start. You requested: {}", req.path());
|
|
Ok(Started::Done)
|
|
}
|
|
|
|
fn response(&self, _req: &HttpRequest<S>, resp: HttpResponse) -> Result<Response> {
|
|
println!("Hi from response");
|
|
Ok(Response::Done(resp))
|
|
}
|
|
|
|
fn finish(&self, _req: &HttpRequest<S>, _resp: &HttpResponse) -> Finished {
|
|
println!("Hi from finish");
|
|
Finished::Done
|
|
}
|
|
}
|