aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-registry
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-02-22 15:23:52 +0900
committernsfisis <nsfisis@gmail.com>2026-02-22 15:23:52 +0900
commit7f75c394502d32a9a8967dcf3602141098fdd07d (patch)
treea608e90009d5664933fc5bba3cd08a5c7d2e5a48 /crates/mozart-registry
parent0a6bafc75f329910bcaeb7d83feee3f9b01db66b (diff)
downloadphp-mozart-7f75c394502d32a9a8967dcf3602141098fdd07d.tar.gz
php-mozart-7f75c394502d32a9a8967dcf3602141098fdd07d.tar.zst
php-mozart-7f75c394502d32a9a8967dcf3602141098fdd07d.zip
refactor(http): centralize User-Agent string in mozart-core
Add mozart_core::http::user_agent() that returns a consistent "Mozart/<version> (<os>; <arch>)" string. Replace all scattered user-agent definitions across mozart-registry and mozart CLI commands. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'crates/mozart-registry')
-rw-r--r--crates/mozart-registry/src/downloader.rs5
-rw-r--r--crates/mozart-registry/src/packagist.rs9
2 files changed, 10 insertions, 4 deletions
diff --git a/crates/mozart-registry/src/downloader.rs b/crates/mozart-registry/src/downloader.rs
index 9a5ed24..8bd99c7 100644
--- a/crates/mozart-registry/src/downloader.rs
+++ b/crates/mozart-registry/src/downloader.rs
@@ -108,7 +108,10 @@ pub async fn download_dist(
}
}
- let response = reqwest::get(url).await?;
+ let client = reqwest::Client::builder()
+ .user_agent(mozart_core::http::user_agent())
+ .build()?;
+ let response = client.get(url).send().await?;
if !response.status().is_success() {
anyhow::bail!(
diff --git a/crates/mozart-registry/src/packagist.rs b/crates/mozart-registry/src/packagist.rs
index e851955..ac290fb 100644
--- a/crates/mozart-registry/src/packagist.rs
+++ b/crates/mozart-registry/src/packagist.rs
@@ -215,7 +215,10 @@ pub async fn fetch_package_versions(
// Cache miss — fetch from Packagist
let url = format!("https://repo.packagist.org/p2/{package_name}.json");
- let response = reqwest::get(&url).await?;
+ let client = reqwest::Client::builder()
+ .user_agent(mozart_core::http::user_agent())
+ .build()?;
+ let response = client.get(&url).send().await?;
if !response.status().is_success() {
anyhow::bail!(
@@ -285,7 +288,7 @@ pub async fn search_packages(
package_type: Option<&str>,
) -> anyhow::Result<(Vec<SearchResult>, u64)> {
let client = reqwest::Client::builder()
- .user_agent("mozart/0.1.0")
+ .user_agent(mozart_core::http::user_agent())
.build()?;
let mut all_results: Vec<SearchResult> = Vec::new();
@@ -396,7 +399,7 @@ pub async fn fetch_security_advisories(
package_names: &[&str],
) -> anyhow::Result<BTreeMap<String, Vec<SecurityAdvisory>>> {
let client = reqwest::Client::builder()
- .user_agent("mozart/0.1.0")
+ .user_agent(mozart_core::http::user_agent())
.build()?;
let mut all_advisories: BTreeMap<String, Vec<SecurityAdvisory>> = BTreeMap::new();