Add a common way to create HTTP client (#3110)

Ensure User-Agent and originator are always sent.
This commit is contained in:
pakrym-oai
2025-09-03 10:11:02 -07:00
committed by GitHub
parent af338cc505
commit c636f821ae
15 changed files with 218 additions and 99 deletions

View File

@@ -301,7 +301,11 @@ async fn run_ratatui_app(
let Cli { prompt, images, .. } = cli;
let auth_manager = AuthManager::shared(config.codex_home.clone(), config.preferred_auth_method);
let auth_manager = AuthManager::shared(
config.codex_home.clone(),
config.preferred_auth_method,
config.responses_originator_header.clone(),
);
let login_status = get_login_status(&config);
let should_show_onboarding =
should_show_onboarding(login_status, &config, should_show_trust_screen);
@@ -357,7 +361,11 @@ fn get_login_status(config: &Config) -> LoginStatus {
// Reading the OpenAI API key is an async operation because it may need
// to refresh the token. Block on it.
let codex_home = config.codex_home.clone();
match CodexAuth::from_codex_home(&codex_home, config.preferred_auth_method) {
match CodexAuth::from_codex_home(
&codex_home,
config.preferred_auth_method,
&config.responses_originator_header,
) {
Ok(Some(auth)) => LoginStatus::AuthMode(auth.mode),
Ok(None) => LoginStatus::NotAuthenticated,
Err(err) => {

View File

@@ -9,7 +9,7 @@ use std::path::Path;
use std::path::PathBuf;
use codex_core::config::Config;
use codex_core::user_agent::get_codex_user_agent;
use codex_core::default_client::create_client;
pub fn get_upgrade_version(config: &Config) -> Option<String> {
let version_file = version_filepath(config);
@@ -22,8 +22,9 @@ pub fn get_upgrade_version(config: &Config) -> Option<String> {
// Refresh the cached latest version in the background so TUI startup
// isnt blocked by a network call. The UI reads the previously cached
// value (if any) for this run; the next run shows the banner if needed.
let originator = config.responses_originator_header.clone();
tokio::spawn(async move {
check_for_update(&version_file)
check_for_update(&version_file, &originator)
.await
.inspect_err(|e| tracing::error!("Failed to update version: {e}"))
});
@@ -63,12 +64,11 @@ fn read_version_info(version_file: &Path) -> anyhow::Result<VersionInfo> {
Ok(serde_json::from_str(&contents)?)
}
async fn check_for_update(version_file: &Path) -> anyhow::Result<()> {
async fn check_for_update(version_file: &Path, originator: &str) -> anyhow::Result<()> {
let ReleaseInfo {
tag_name: latest_tag_name,
} = reqwest::Client::new()
} = create_client(originator)
.get(LATEST_RELEASE_URL)
.header("User-Agent", get_codex_user_agent(None))
.send()
.await?
.error_for_status()?