diff options
author | metamuffin <metamuffin@disroot.org> | 2024-11-26 17:28:27 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-17 15:48:15 +0100 |
commit | 6b1d06e8af908175803060fedd9d1b7be9c92a40 (patch) | |
tree | 53a3f58f1ee44a8486b04bdf293fb45411058baf | |
parent | e9a31a5246c27fc8fa31bb08b367d1a42d8bb557 (diff) | |
download | gnix-6b1d06e8af908175803060fedd9d1b7be9c92a40.tar gnix-6b1d06e8af908175803060fedd9d1b7be9c92a40.tar.bz2 gnix-6b1d06e8af908175803060fedd9d1b7be9c92a40.tar.zst |
inspect node for debugging
-rw-r--r-- | src/modules/inspect.rs | 42 | ||||
-rw-r--r-- | src/modules/mod.rs | 2 |
2 files changed, 44 insertions, 0 deletions
diff --git a/src/modules/inspect.rs b/src/modules/inspect.rs new file mode 100644 index 0000000..1ad6522 --- /dev/null +++ b/src/modules/inspect.rs @@ -0,0 +1,42 @@ +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(), + ); + Ok(self.next.handle(context, request).await?) + }) + } +} diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 7470725..6f945af 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -17,6 +17,7 @@ mod file; mod files; mod headers; mod hosts; +mod inspect; mod loadbalance; mod paths; mod proxy; @@ -46,6 +47,7 @@ pub static MODULES: &[&dyn NodeKind] = &[ &cache::CacheKind, &loadbalance::LoadBalanceKind, &upgrade_insecure::UpgradeInsecureKind, + &inspect::InspectKind, ]; pub struct NodeContext { |