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
|
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
})
}
}
|