Always set user agent (#805)

* Always set user agent

* more
This commit is contained in:
Logan McNaughton
2026-04-24 23:15:47 -06:00
committed by GitHub
parent ae4e7cb01f
commit 65c63dfc5d
4 changed files with 17 additions and 21 deletions
+2 -13
View File
@@ -2,17 +2,6 @@ include!(concat!(env!("OUT_DIR"), "/retroachievements_bindings.rs"));
use crate::ui;
static WEB_CLIENT: std::sync::LazyLock<reqwest::Client> = std::sync::LazyLock::new(|| {
reqwest::Client::builder()
.user_agent(format!(
"{}/{}",
env!("CARGO_PKG_NAME"),
env!("GIT_DESCRIBE")
))
.build()
.unwrap()
});
#[derive(serde::Serialize, serde::Deserialize)]
pub struct RAConfig {
pub username: String,
@@ -85,13 +74,13 @@ pub extern "C" fn rust_server_call(
unsafe { std::ffi::CStr::from_ptr(c_post_data).to_str().unwrap() }.to_string();
let content_type =
unsafe { std::ffi::CStr::from_ptr(c_content_type).to_str().unwrap() }.to_string();
WEB_CLIENT
ui::WEB_CLIENT
.post(url)
.body(post_data)
.header(reqwest::header::CONTENT_TYPE, content_type)
.send()
} else {
WEB_CLIENT.get(url).send()
ui::WEB_CLIENT.get(url).send()
};
let callback = c_callback.addr();
let callback_data = c_callback_data.addr();
+11
View File
@@ -15,6 +15,17 @@ pub mod video;
#[cfg(feature = "gui")]
pub mod vru;
pub static WEB_CLIENT: std::sync::LazyLock<reqwest::Client> = std::sync::LazyLock::new(|| {
reqwest::Client::builder()
.user_agent(format!(
"{}/{}",
env!("CARGO_PKG_NAME"),
env!("GIT_DESCRIBE")
))
.build()
.unwrap()
});
pub struct Dirs {
pub config_dir: std::path::PathBuf,
pub data_dir: std::path::PathBuf,
+1 -5
View File
@@ -28,11 +28,7 @@ pub struct RASettings {
}
fn check_latest_version(weak: slint::Weak<AppWindow>) {
let client = reqwest::Client::builder()
.user_agent(env!("CARGO_PKG_NAME"))
.build()
.unwrap();
let task = client
let task = ui::WEB_CLIENT
.get("https://api.github.com/repos/gopher64/gopher64/releases/latest")
.send();
tokio::spawn(async move {
+3 -3
View File
@@ -109,7 +109,7 @@ impl NetplayPages for NetplayJoin {
}
fn populate_server_names<T: ComponentHandle + NetplayPages + 'static>(weak: slint::Weak<T>) {
let task = reqwest::Client::new()
let task = ui::WEB_CLIENT
.get("https://dispatch.gopher64.com/getRegions")
.header("netplay-id", env!("NETPLAY_ID"))
.send();
@@ -292,7 +292,7 @@ pub fn setup_create_window(
let weak_dialog = message_dialog.as_weak();
message_dialog.show().unwrap();
let task = reqwest::Client::new()
let task = ui::WEB_CLIENT
.get("https://dispatch.gopher64.com/createServer")
.query(&[("region", server_url.strip_prefix("dispatcher:").unwrap())])
.header("netplay-id", env!("NETPLAY_ID"))
@@ -448,7 +448,7 @@ fn show_netplay_error(message: String) {
}
fn update_sessions(weak: slint::Weak<NetplayJoin>) {
let task = reqwest::Client::new()
let task = ui::WEB_CLIENT
.get("https://dispatch.gopher64.com/getServers")
.header("netplay-id", env!("NETPLAY_ID"))
.send();