/* 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 */ use super::{Node, NodeContext, NodeKind, NodeRequest, NodeResponse}; use crate::error::ServiceError; use futures::Future; use http::{header::CONTENT_TYPE, HeaderValue, Response}; use http_body_util::BodyExt; use serde::Deserialize; use serde_yml::Value; use std::{pin::Pin, sync::Arc}; pub struct DebugKind; #[derive(Deserialize)] struct Debug; impl NodeKind for DebugKind { fn name(&self) -> &'static str { "debug" } fn instanciate(&self, config: Value) -> anyhow::Result> { Ok(Arc::new(serde_yml::from_value::(config)?)) } } impl Node for Debug { fn handle<'a>( &'a self, context: &'a mut NodeContext, request: NodeRequest, ) -> Pin> + Send + Sync + 'a>> { Box::pin(async move { let s = format!( "address: {:?}\nversion: {:?}\nmethod: {:?}\nuri: {:?}\nheaders: {:#?}", context.addr, request.version(), request.method(), request.uri(), request.headers(), ); let mut r = Response::new(s); r.headers_mut() .insert(CONTENT_TYPE, HeaderValue::from_static("text/plain")); Ok(r.map(|b| b.map_err(|e| match e {}).boxed())) }) } }