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 <amrbashir@users.noreply.github.com>
This commit is contained in:
Amr Bashir
2024-11-21 15:09:42 +00:00
committed by tauri-bot
parent dd1f2edcbe
commit 0641887f33
2 changed files with 11 additions and 0 deletions

View File

@@ -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"]

View File

@@ -283,6 +283,9 @@ pub async fn fetch<R: Runtime>(
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<R: Runtime>(
.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<R: Runtime>(
}
};
#[cfg(feature = "tracing")]
tracing::trace!("{:?}", res);
let status = res.status();
let url = res.url().to_string();
let mut headers = Vec::new();