diff --git a/Cargo.lock b/Cargo.lock index f247be9..014ca40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1682,6 +1682,7 @@ version = "0.1.0" dependencies = [ "async-trait", "base64 0.22.0", + "bytes", "http 1.1.0", "log", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index 5518432..17799fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,4 @@ p256 = "0.13.2" p384 = "0.13.0" p521 = "0.13.3" once_cell = "1.19.0" +bytes = "1.6.0" diff --git a/src/app.rs b/src/app.rs index 83c3639..037690a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,8 +1,10 @@ use async_trait::async_trait; use base64::Engine; use base64::engine::general_purpose::STANDARD; +use bytes::Bytes; use http::HeaderName; use pingora::{Error, ErrorType}; +use pingora::http::ResponseHeader; use pingora::prelude::{HttpPeer, ProxyHttp, Result, Session}; use super::service::HostConfig; @@ -83,4 +85,34 @@ impl ProxyHttp for ProxyApp { log::info!("Request:\n{}\n\n{}", req, body.unwrap_or_else(|| "".into())); Ok(false) } + + async fn response_filter( + &self, + _session: &mut Session, + upstream_response: &mut ResponseHeader, + _ctx: &mut Self::CTX, + ) -> Result<()> + where Self::CTX: Send + Sync, + { + let mut resp = String::new(); + resp.push_str(&format!("version: {}\n", upstream_response.status)); + resp.push_str(&format!("headers: {:#?}", upstream_response.headers)); + + log::info!("Response: {}", resp); + Ok(()) + } + + fn upstream_response_body_filter( + &self, + _session: &mut Session, + body: &Option, + end_of_stream: bool, + _ctx: &mut Self::CTX, + ) { + log::info!("Body {}: [[[{}]]] ",end_of_stream, + body.as_ref().map(|bytes| + String::from_utf8_lossy(bytes.iter().as_slice()) + ).unwrap_or_else(|| "".into()) + ); + } } \ No newline at end of file