From 5adcc3cbcc79fe09cb663553a596ec9dc134651b Mon Sep 17 00:00:00 2001 From: amrbashir Date: Wed, 20 Nov 2024 04:35:47 +0200 Subject: [PATCH] feat(http): add request and response tracing behind feature flag closes #2055 --- .changes/http-tracing.md | 5 +++++ Cargo.lock | 1 + plugins/http/Cargo.toml | 2 ++ plugins/http/src/commands.rs | 9 +++++++++ 4 files changed, 17 insertions(+) create mode 100644 .changes/http-tracing.md diff --git a/.changes/http-tracing.md b/.changes/http-tracing.md new file mode 100644 index 000000000..5ad02a9ca --- /dev/null +++ b/.changes/http-tracing.md @@ -0,0 +1,5 @@ +--- +"http": "patch" +--- + +Add tracing logs for requestes and responses behind `tracing` feature flag. \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index fc2070547..90935c537 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6615,6 +6615,7 @@ version = "2.0.3" dependencies = [ "data-url", "http", + "log", "regex", "reqwest", "schemars", diff --git a/plugins/http/Cargo.toml b/plugins/http/Cargo.toml index 8c1801a38..d02098df7 100644 --- a/plugins/http/Cargo.toml +++ b/plugins/http/Cargo.toml @@ -41,6 +41,7 @@ http = "1" reqwest = { version = "0.12", default-features = false } url = { workspace = true } data-url = "0.3" +log = { workspace = true, optional = true } [features] default = [ @@ -71,3 +72,4 @@ http2 = ["reqwest/http2"] charset = ["reqwest/charset"] macos-system-configuration = ["reqwest/macos-system-configuration"] unsafe-headers = [] +tracing = ["dep:log"] diff --git a/plugins/http/src/commands.rs b/plugins/http/src/commands.rs index f4bc3aabc..bdeb74e1a 100644 --- a/plugins/http/src/commands.rs +++ b/plugins/http/src/commands.rs @@ -283,6 +283,9 @@ pub async fn fetch( request = request.headers(headers); + #[cfg(feature = "tracing")] + log::trace!("{:?}", request); + let fut = async move { request.send().await.map_err(Into::into) }; let mut resources_table = webview.resources_table(); let rid = resources_table.add_request(Box::pin(fut)); @@ -304,6 +307,9 @@ pub async fn fetch( .header(header::CONTENT_TYPE, data_url.mime_type().to_string()) .body(reqwest::Body::from(body))?; + #[cfg(feature = "tracing")] + log::trace!("{:?}", response); + let fut = async move { Ok(reqwest::Response::from(response)) }; let mut resources_table = webview.resources_table(); let rid = resources_table.add_request(Box::pin(fut)); @@ -351,6 +357,9 @@ pub async fn fetch_send( } }; + #[cfg(feature = "tracing")] + log::trace!("{:?}", res); + let status = res.status(); let url = res.url().to_string(); let mut headers = Vec::new();