Skip to content

Commit

Permalink
feat: add user-agent to rattler-build client (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Mar 6, 2024
1 parent a5e35dd commit f01d5c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/tool_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use std::{path::PathBuf, sync::Arc};
use crate::console_utils::LoggingOutputHandler;
use rattler_networking::{authentication_storage, AuthenticationMiddleware, AuthenticationStorage};
use reqwest_middleware::ClientWithMiddleware;

/// The user agent to use for the reqwest client
pub const APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);

/// Global configuration for the build
#[derive(Clone, Debug)]
pub struct Configuration {
Expand Down Expand Up @@ -45,9 +49,14 @@ pub fn get_auth_store(auth_file: Option<PathBuf>) -> AuthenticationStorage {
/// Create a reqwest client with the authentication middleware
pub fn reqwest_client_from_auth_storage(auth_file: Option<PathBuf>) -> ClientWithMiddleware {
let auth_storage = get_auth_store(auth_file);

let timeout = 5 * 60;
reqwest_middleware::ClientBuilder::new(
reqwest::Client::builder()
.no_gzip()
.pool_max_idle_per_host(20)
.user_agent(APP_USER_AGENT)
.timeout(std::time::Duration::from_secs(timeout))
.build()
.expect("failed to create client"),
)
Expand All @@ -59,16 +68,7 @@ impl Default for Configuration {
fn default() -> Self {
Self {
fancy_log_handler: LoggingOutputHandler::default(),
client: reqwest_middleware::ClientBuilder::new(
reqwest::Client::builder()
.no_gzip()
.build()
.expect("failed to create client"),
)
.with_arc(Arc::new(AuthenticationMiddleware::new(
AuthenticationStorage::default(),
)))
.build(),
client: reqwest_client_from_auth_storage(None),
no_clean: false,
no_test: false,
use_zstd: true,
Expand Down
3 changes: 2 additions & 1 deletion src/upload/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use futures::TryStreamExt;
use indicatif::{style::TemplateError, HumanBytes, ProgressState};
use rattler_build::tool_configuration::APP_USER_AGENT;
use std::{
fmt::Write,
path::{Path, PathBuf},
Expand Down Expand Up @@ -42,7 +43,7 @@ fn default_bytes_style() -> Result<indicatif::ProgressStyle, TemplateError> {
fn get_default_client() -> Result<reqwest::Client, reqwest::Error> {
reqwest::Client::builder()
.no_gzip()
.user_agent(format!("rattler-build/{}", VERSION))
.user_agent(APP_USER_AGENT)
.build()
}

Expand Down

0 comments on commit f01d5c7

Please sign in to comment.