From 0641887f33c4d7aa0727c2297fc28c99b6624cff Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Thu, 21 Nov 2024 15:09:42 +0000 Subject: [PATCH] feat(http): add request and response tracing behind feature flag (#2079) Committed via a GitHub action: https://github.com/tauri-apps/plugins-workspace/actions/runs/11956038248 Co-authored-by: amrbashir --- Cargo.toml | 2 ++ src/commands.rs | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 8c1801a..d7bcb9c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ http = "1" reqwest = { version = "0.12", default-features = false } url = { workspace = true } data-url = "0.3" +tracing = { 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:tracing"] diff --git a/src/commands.rs b/src/commands.rs index f4bc3aa..03c84ad 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -283,6 +283,9 @@ pub async fn fetch( request = request.headers(headers); + #[cfg(feature = "tracing")] + tracing::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")] + tracing::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")] + tracing::trace!("{:?}", res); + let status = res.status(); let url = res.url().to_string(); let mut headers = Vec::new();