Add user agent for http requests (closes #12)

This commit is contained in:
Bnyro 2023-07-01 10:04:06 +02:00
parent 18492e0685
commit ae6bf45879
1 changed files with 10 additions and 4 deletions

View File

@ -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<Client> = Lazy::new(|| Client::new());
pub static CLIENT: Lazy<Client> = 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()