Include OS in theseus User-Agent (#5046)

This commit is contained in:
François-Xavier Talbot
2026-01-07 21:11:18 -05:00
committed by GitHub
parent a1d9268d00
commit 17db55a0bc
3 changed files with 14 additions and 9 deletions

View File

@@ -26,8 +26,13 @@ pub use event::{
pub use logger::start_logger; pub use logger::start_logger;
pub use state::State; pub use state::State;
pub const LAUNCHER_USER_AGENT: &str = concat!( pub fn launcher_user_agent() -> String {
"modrinth/theseus/", const LAUNCHER_BASE_USER_AGENT: &str =
env!("CARGO_PKG_VERSION"), concat!("modrinth/theseus/", env!("CARGO_PKG_VERSION"),);
" (support@modrinth.com)"
); format!(
"{} ({}; support@modrinth.com)",
LAUNCHER_BASE_USER_AGENT,
std::env::consts::OS
)
}

View File

@@ -1,5 +1,4 @@
use crate::ErrorKind; use crate::ErrorKind;
use crate::LAUNCHER_USER_AGENT;
use crate::data::ModrinthCredentials; use crate::data::ModrinthCredentials;
use crate::event::FriendPayload; use crate::event::FriendPayload;
use crate::event::emit::emit_friend; use crate::event::emit::emit_friend;
@@ -85,7 +84,7 @@ impl FriendsSocket {
request.headers_mut().insert( request.headers_mut().insert(
"User-Agent", "User-Agent",
HeaderValue::from_str(LAUNCHER_USER_AGENT).unwrap(), HeaderValue::from_str(&crate::launcher_user_agent()).unwrap(),
); );
let res = connect_async(request).await; let res = connect_async(request).await;

View File

@@ -1,7 +1,6 @@
//! Functions for fetching information from the Internet //! Functions for fetching information from the Internet
use super::io::{self, IOError}; use super::io::{self, IOError};
use crate::ErrorKind; use crate::ErrorKind;
use crate::LAUNCHER_USER_AGENT;
use crate::event::LoadingBarId; use crate::event::LoadingBarId;
use crate::event::emit::emit_loading; use crate::event::emit::emit_loading;
use bytes::Bytes; use bytes::Bytes;
@@ -21,8 +20,10 @@ pub struct FetchSemaphore(pub Semaphore);
pub static REQWEST_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(|| { pub static REQWEST_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(|| {
let mut headers = reqwest::header::HeaderMap::new(); let mut headers = reqwest::header::HeaderMap::new();
let header = let header =
reqwest::header::HeaderValue::from_str(LAUNCHER_USER_AGENT).unwrap(); reqwest::header::HeaderValue::from_str(&crate::launcher_user_agent())
.unwrap();
headers.insert(reqwest::header::USER_AGENT, header); headers.insert(reqwest::header::USER_AGENT, header);
reqwest::Client::builder() reqwest::Client::builder()
.tcp_keepalive(Some(time::Duration::from_secs(10))) .tcp_keepalive(Some(time::Duration::from_secs(10)))