Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add user agent to pixi http client #892

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cli/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ pub async fn execute(args: Args) -> miette::Result<()> {
#[cfg(target_family = "windows")]
let res = match interactive_shell {
ShellEnum::NuShell(nushell) => {
start_nu_shell(nushell, &env, prompt::get_nu_prompt(prompt_name.as_str())).await
start_nu_shell(nushell, env, prompt::get_nu_prompt(prompt_name.as_str())).await
}
ShellEnum::PowerShell(pwsh) => start_powershell(
pwsh,
&env,
env,
prompt::get_powershell_prompt(prompt_name.as_str()),
),
ShellEnum::CmdExe(cmdexe) => {
start_cmdexe(cmdexe, &env, prompt::get_cmd_prompt(prompt_name.as_str()))
start_cmdexe(cmdexe, env, prompt::get_cmd_prompt(prompt_name.as_str()))
}
_ => {
miette::bail!("Unsupported shell: {:?}", interactive_shell);
Expand Down
34 changes: 20 additions & 14 deletions src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,7 @@ impl Debug for Project {
impl Project {
/// Constructs a new instance from an internal manifest representation
pub fn from_manifest(manifest: Manifest) -> Self {
let client = reqwest::Client::new();
let authenticated_client = reqwest_middleware::ClientBuilder::new(reqwest::Client::new())
.with_arc(Arc::new(AuthenticationMiddleware::default()))
.build();
let (client, authenticated_client) = build_reqwest_clients();

let env_vars = Project::init_env_vars(&manifest.parsed.environments);

Expand Down Expand Up @@ -191,16 +188,7 @@ impl Project {

let env_vars = Project::init_env_vars(&manifest.parsed.environments);

let timeout = 5 * 60;
let client = Client::builder()
.pool_max_idle_per_host(20)
.timeout(std::time::Duration::from_secs(timeout))
.build()
.expect("failed to create reqwest Client");

let authenticated_client = reqwest_middleware::ClientBuilder::new(client.clone())
.with_arc(Arc::new(AuthenticationMiddleware::default()))
.build();
let (client, authenticated_client) = build_reqwest_clients();

Ok(Self {
root: root.to_owned(),
Expand Down Expand Up @@ -471,6 +459,24 @@ impl Project {
}
}

fn build_reqwest_clients() -> (Client, ClientWithMiddleware) {
static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);

let timeout = 5 * 60;
let client = Client::builder()
.pool_max_idle_per_host(20)
.user_agent(APP_USER_AGENT)
.timeout(std::time::Duration::from_secs(timeout))
.build()
.expect("failed to create reqwest Client");

let authenticated_client = reqwest_middleware::ClientBuilder::new(client.clone())
.with_arc(Arc::new(AuthenticationMiddleware::default()))
.build();

(client, authenticated_client)
}

/// Iterates over the current directory and all its parent directories and returns the first
/// directory path that contains the [`consts::PROJECT_MANIFEST`].
pub fn find_project_root() -> Option<PathBuf> {
Expand Down
Loading