log http requests that go via send

This commit is contained in:
psykose 2024-11-16 12:28:37 +01:00
parent ee532e5abb
commit 2362ca4e7a
Signed by: psykose
SSH key fingerprint: SHA256:pRMVjV3kRB6zl+wNx+sV8KoMnPqQAW6v8dNCxsCGZv8

View file

@ -111,16 +111,18 @@ impl Client {
async fn send<T: serde::de::DeserializeOwned + Send + 'static>( async fn send<T: serde::de::DeserializeOwned + Send + 'static>(
&self, &self,
request: reqwest::RequestBuilder, request: reqwest::Request,
) -> Result<T, Error> { ) -> Result<T, Error> {
// FIXME: is an entire channel per request overkill? maybe pool them? // FIXME: is an entire channel per request overkill? maybe pool them?
let (sender, receiver) = async_channel::bounded(1); let (sender, receiver) = async_channel::bounded(1);
event!(target: "http_request", Level::DEBUG, method = request.method().as_str(), url = request.url().as_str());
// let tokio take care of the request + further json parsing // let tokio take care of the request + further json parsing
// this is because reqwest doesn't like the glib main loop // this is because reqwest doesn't like the glib main loop
// note that this is why those silly bounds on T are needed, because we're // note that this is why those silly bounds on T are needed, because we're
// sending back the result of the query from another thread // sending back the result of the query from another thread
let future = request.send(); let future = self.client.execute(request);
runtime().spawn(async move { runtime().spawn(async move {
// wrap this logic in a fn so we can use ? // wrap this logic in a fn so we can use ?
async fn perform<T: serde::de::DeserializeOwned + Send + 'static>( async fn perform<T: serde::de::DeserializeOwned + Send + 'static>(
@ -165,7 +167,8 @@ impl Client {
path: &[&str], path: &[&str],
query: &[(&str, &str)], query: &[(&str, &str)],
) -> Result<T, Error> { ) -> Result<T, Error> {
self.send(self.client.get(self.url(path, query))).await self.send(self.client.get(self.url(path, query)).build()?)
.await
} }
pub async fn ping(&self) -> Result<(), Error> { pub async fn ping(&self) -> Result<(), Error> {