diff --git a/lib/sources/client.rs b/lib/sources/client.rs index 4dcd7c5..9ae548d 100644 --- a/lib/sources/client.rs +++ b/lib/sources/client.rs @@ -1,6 +1,10 @@ use std::time::Duration; -use reqwest::{header::HeaderMap, Client, Error}; +use reqwest::{ + header::{HeaderMap, USER_AGENT}, + Client, Error, +}; + use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; use reqwest_retry::{policies::ExponentialBackoff, RetryTransientMiddleware}; use reqwest_tracing::TracingMiddleware; @@ -26,8 +30,18 @@ fn add_client_middleware(client: Client) -> ClientWithMiddleware { - HTTPS only - Timeouts for connection and response - All common compression algorithms enabled + - User agent set to `/ ()` */ -pub fn create_client(default_headers: HeaderMap) -> Result { +pub fn create_client(mut default_headers: HeaderMap) -> Result { + let user_agent = format!( + "{}/{} ({})", + env!("CARGO_PKG_NAME"), + env!("CARGO_PKG_VERSION"), + env!("CARGO_PKG_REPOSITORY"), + ); + + default_headers.insert(USER_AGENT, user_agent.parse().unwrap()); + let client = Client::builder() .default_headers(default_headers) .https_only(true) @@ -37,5 +51,6 @@ pub fn create_client(default_headers: HeaderMap) -> Result