Include version and contact information in GitHub User Agent (#10785)

## Summary

See: https://github.com/astral-sh/uv/pull/10765#discussion_r1922016112
This commit is contained in:
Charlie Marsh 2025-01-20 14:30:04 -05:00 committed by GitHub
parent 5ee4cf6ff5
commit 25982929c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 4 deletions

1
Cargo.lock generated
View file

@ -5117,6 +5117,7 @@ dependencies = [
"uv-cache-key",
"uv-fs",
"uv-static",
"uv-version",
"which",
]

View file

@ -20,6 +20,7 @@ uv-cache-key = { workspace = true }
uv-fs = { workspace = true, features = ["tokio"] }
uv-auth = { workspace = true }
uv-static = { workspace = true}
uv-version = { workspace = true }
anyhow = { workspace = true }
cargo-util = { workspace = true }

View file

@ -16,6 +16,7 @@ use url::Url;
use uv_fs::Simplified;
use uv_static::EnvVars;
use uv_version::version;
use crate::sha::GitOid;
use crate::{GitHubRepository, GitSha};
@ -782,7 +783,10 @@ fn github_fast_path(
debug!("Attempting GitHub fast path for: {url}");
let mut request = client.get(&url);
request = request.header("Accept", "application/vnd.github.3.sha");
request = request.header("User-Agent", "uv");
request = request.header(
"User-Agent",
format!("uv/{} (+https://github.com/astral-sh/uv)", version()),
);
if let Some(local_object) = local_object {
request = request.header("If-None-Match", local_object.to_string());
}

View file

@ -5,14 +5,14 @@ use std::sync::Arc;
use tracing::debug;
use crate::{Fetch, GitHubRepository, GitReference, GitSha, GitSource, GitUrl, Reporter};
use dashmap::mapref::one::Ref;
use dashmap::DashMap;
use fs_err::tokio as fs;
use reqwest_middleware::ClientWithMiddleware;
use uv_cache_key::{cache_digest, RepositoryUrl};
use uv_fs::LockedFile;
use crate::{Fetch, GitHubRepository, GitReference, GitSha, GitSource, GitUrl, Reporter};
use uv_version::version;
#[derive(Debug, thiserror::Error)]
pub enum GitResolverError {
@ -73,7 +73,10 @@ impl GitResolver {
debug!("Attempting GitHub fast path for: {url}");
let mut request = client.get(&url);
request = request.header("Accept", "application/vnd.github.3.sha");
request = request.header("User-Agent", "uv");
request = request.header(
"User-Agent",
format!("uv/{} (+https://github.com/astral-sh/uv)", version()),
);
let response = request.send().await?;
if !response.status().is_success() {