1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use async_trait::async_trait;

use crate::app::EndpointExecutor;
use crate::context::Context;
use crate::middleware::Middleware;
use crate::router::ContextResult;

#[derive(Default)]
pub struct Logger {}

impl Logger {
    pub fn new() -> Self {
        Logger {}
    }
}

#[async_trait]
impl Middleware for Logger {
    async fn handle<'a>(
        &'a self,
        context: Context,
        ep_executor: EndpointExecutor<'a>,
    ) -> ContextResult {
        println!(
            "{} {} \n{}",
            context.method(),
            context.uri(),
            context.headers().get("host").unwrap().to_str().unwrap()
        );

        ep_executor.next(context).await
    }
}