diff --git a/src/download.rs b/src/download.rs index 8d45e3f..5a8dfad 100644 --- a/src/download.rs +++ b/src/download.rs @@ -6,6 +6,8 @@ use std::io::{Read, Seek, SeekFrom, Write}; use std::path::Path; use std::time::Instant; +use crate::user_agent::APP_USER_AGENT; + pub fn download_file(url: &str, file_path: &Path, redirect_path: &Path) -> Result<()> { if let Some(dir) = file_path.parent() { fs::create_dir_all(dir)?; @@ -20,6 +22,7 @@ pub fn download_file(url: &str, file_path: &Path, redirect_path: &Path) -> Resul let file_size = file.metadata()?.len(); let client = Client::builder() + .user_agent(APP_USER_AGENT) .timeout(std::time::Duration::from_secs(30)) .build()?; let mut response = client diff --git a/src/main.rs b/src/main.rs index 3d8387a..a86ac01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ mod reader_with_bytes; mod reader_with_progress; mod sql; mod unpack; +mod user_agent; mod utils; use checksum::*; diff --git a/src/user_agent.rs b/src/user_agent.rs new file mode 100644 index 0000000..f9d4857 --- /dev/null +++ b/src/user_agent.rs @@ -0,0 +1,5 @@ +pub static APP_USER_AGENT: &str = concat!( + env!("CARGO_PKG_NAME"), + "/", + env!("CARGO_PKG_VERSION"), +); \ No newline at end of file diff --git a/src/utils.rs b/src/utils.rs index 3c40257..929c127 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -5,6 +5,8 @@ use reqwest::{blocking::Client, redirect}; use std::{env, path::PathBuf}; use url::Url; +use crate::user_agent::APP_USER_AGENT; + pub fn strip_trailing_newline(input: &str) -> &str { input.trim_end() } @@ -73,6 +75,7 @@ fn extract_number_from_url(url: &Url) -> Result { pub fn fetch_latest_available_layer(download_url: &Url, go_version: &str) -> Result { let client = Client::builder() + .user_agent(APP_USER_AGENT) .redirect(redirect::Policy::none()) .timeout(std::time::Duration::from_secs(30)) .build()?;