From ae6bf45879292ca0f7792868f232e19c021a7a1a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 1 Jul 2023 10:04:06 +0200 Subject: [PATCH] Add user agent for http requests (closes #12) --- src/api/mod.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/api/mod.rs b/src/api/mod.rs index 2afeb98..7c616ee 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,19 +1,19 @@ use serde::{de::DeserializeOwned, Serialize}; -use crate::settings::get_current_account; +use crate::{config, settings::get_current_account}; pub mod auth; pub mod comment; pub mod communities; pub mod community; +pub mod image; +pub mod instances; pub mod moderation; pub mod post; pub mod posts; pub mod private_message; pub mod search; pub mod site; -pub mod image; -pub mod instances; pub mod user; static API_VERSION: &str = "v3"; @@ -21,7 +21,13 @@ static API_VERSION: &str = "v3"; use relm4::once_cell::sync::Lazy; use reqwest::blocking::Client; -pub static CLIENT: Lazy = Lazy::new(|| Client::new()); +pub static CLIENT: Lazy = Lazy::new(|| { + let user_agent = format!("{}/{}", config::NAME, config::VERSION); + Client::builder() + .user_agent(user_agent) + .build() + .expect("Failed to create reqwest http client!") +}); fn get_api_url() -> String { format!("{}/api/{}", get_current_account().instance_url, API_VERSION).to_string()