aboutsummaryrefslogtreecommitdiff
path: root/src/modules/inspect.rs
blob: c9b3abcdd2afe4deb6520bb4245e677198e8b066 (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
    This file is part of gnix (https://codeberg.org/metamuffin/gnix)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2025 metamuffin <metamuffin.org>
*/
use super::{Node, NodeContext, NodeKind, NodeRequest, NodeResponse};
use crate::{config::DynNode, error::ServiceError};
use anyhow::Result;
use futures::Future;
use log::debug;
use serde::Deserialize;
use std::{pin::Pin, sync::Arc};

pub struct InspectKind;

#[derive(Deserialize)]
pub struct Inspect {
    next: DynNode,
}

impl NodeKind for InspectKind {
    fn name(&self) -> &'static str {
        "inspect"
    }
    fn instanciate(&self, config: serde_yml::Value) -> Result<Arc<dyn Node>> {
        Ok(Arc::new(serde_yml::from_value::<Inspect>(config)?))
    }
}

impl Node for Inspect {
    fn handle<'a>(
        &'a self,
        context: &'a mut NodeContext,
        request: NodeRequest,
    ) -> Pin<Box<dyn Future<Output = Result<NodeResponse, ServiceError>> + Send + Sync + 'a>> {
        Box::pin(async move {
            debug!(
                "address: {:?}\nversion: {:?}\nuri: {:?}\nheaders: {:#?}",
                context.addr,
                request.version(),
                request.uri(),
                request.headers(),
            );
            self.next.handle(context, request).await
        })
    }
}