backend-client: route requests through HTTP client factory

This commit is contained in:
Michael Bolin
2026-07-09 15:40:42 -07:00
parent a1484651c4
commit bc76e3ae16
19 changed files with 341 additions and 124 deletions
+7 -2
View File
@@ -95,9 +95,14 @@ impl ConfigManager {
&self,
auth_manager: Arc<AuthManager>,
chatgpt_base_url: String,
http_client_factory: codex_http_client::HttpClientFactory,
) {
let loader =
cloud_config_bundle_loader(auth_manager, chatgpt_base_url, self.codex_home.clone());
let loader = cloud_config_bundle_loader(
auth_manager,
chatgpt_base_url,
self.codex_home.clone(),
http_client_factory,
);
if let Ok(mut guard) = self.cloud_config_bundle.write() {
*guard = loader;
} else {
+5 -2
View File
@@ -505,8 +505,11 @@ pub async fn run_main_with_transport_options(
.replace_thread_config_loader(Arc::clone(&discovered_thread_config_loader));
let auth_manager =
AuthManager::shared_from_config(&config, /*enable_codex_api_key_env*/ false).await;
config_manager
.replace_cloud_config_bundle_loader(auth_manager, config.chatgpt_base_url);
config_manager.replace_cloud_config_bundle_loader(
auth_manager,
config.chatgpt_base_url.clone(),
config.http_client_factory(),
);
}
Err(err) => {
warn!(error = %err, "Failed to preload config for cloud config bundle");
@@ -458,7 +458,7 @@ impl AccountRequestProcessor {
let outgoing_clone = self.outgoing.clone();
let config_manager = self.config_manager.clone();
let thread_manager = Arc::clone(&self.thread_manager);
let chatgpt_base_url = self.config.chatgpt_base_url.clone();
let config = Arc::clone(&self.config);
let active_login = self.active_login.clone();
let auth_url = server.auth_url.clone();
tokio::spawn(async move {
@@ -480,7 +480,7 @@ impl AccountRequestProcessor {
&outgoing_clone,
config_manager,
thread_manager,
chatgpt_base_url,
config,
login_id,
success,
error_msg,
@@ -537,7 +537,7 @@ impl AccountRequestProcessor {
let outgoing_clone = self.outgoing.clone();
let config_manager = self.config_manager.clone();
let thread_manager = Arc::clone(&self.thread_manager);
let chatgpt_base_url = self.config.chatgpt_base_url.clone();
let config = Arc::clone(&self.config);
let active_login = self.active_login.clone();
tokio::spawn(async move {
let (success, error_msg) = tokio::select! {
@@ -556,7 +556,7 @@ impl AccountRequestProcessor {
&outgoing_clone,
config_manager,
thread_manager,
chatgpt_base_url,
config,
login_id,
success,
error_msg,
@@ -671,6 +671,7 @@ impl AccountRequestProcessor {
self.config_manager.replace_cloud_config_bundle_loader(
self.auth_manager.clone(),
self.config.chatgpt_base_url.clone(),
self.config.http_client_factory(),
);
self.config_manager
.sync_default_client_residency_requirement()
@@ -709,7 +710,7 @@ impl AccountRequestProcessor {
outgoing: &OutgoingMessageSender,
config_manager: ConfigManager,
thread_manager: Arc<ThreadManager>,
chatgpt_base_url: String,
config: Arc<Config>,
login_id: Uuid,
success: bool,
error_msg: Option<String>,
@@ -726,8 +727,11 @@ impl AccountRequestProcessor {
if success {
let auth_manager = thread_manager.auth_manager();
auth_manager.reload().await;
config_manager
.replace_cloud_config_bundle_loader(auth_manager.clone(), chatgpt_base_url);
config_manager.replace_cloud_config_bundle_loader(
auth_manager.clone(),
config.chatgpt_base_url.clone(),
config.http_client_factory(),
);
config_manager
.sync_default_client_residency_requirement()
.await;
@@ -933,8 +937,11 @@ impl AccountRequestProcessor {
));
}
let client = BackendClient::from_auth(self.config.chatgpt_base_url.clone(), &auth)
.map_err(|err| internal_error(format!("failed to construct backend client: {err}")))?;
let client = BackendClient::from_auth(
self.config.chatgpt_base_url.clone(),
&auth,
self.config.http_client_factory(),
);
let (response, detailed_rate_limit_reset_credits) = tokio::join!(
client.get_rate_limits_with_reset_credits(),
@@ -1003,8 +1010,11 @@ impl AccountRequestProcessor {
));
}
let client = BackendClient::from_auth(self.config.chatgpt_base_url.clone(), &auth)
.map_err(|err| internal_error(format!("failed to construct backend client: {err}")))?;
let client = BackendClient::from_auth(
self.config.chatgpt_base_url.clone(),
&auth,
self.config.http_client_factory(),
);
let profile = tokio::time::timeout(
ACCOUNT_TOKEN_USAGE_FETCH_TIMEOUT,
client.get_token_usage_profile(),
@@ -1030,8 +1040,11 @@ impl AccountRequestProcessor {
));
}
let client = BackendClient::from_auth(self.config.chatgpt_base_url.clone(), &auth)
.map_err(|err| internal_error(format!("failed to construct backend client: {err}")))?;
let client = BackendClient::from_auth(
self.config.chatgpt_base_url.clone(),
&auth,
self.config.http_client_factory(),
);
let messages = tokio::time::timeout(
ACCOUNT_WORKSPACE_MESSAGES_FETCH_TIMEOUT,
client.list_workspace_messages(),
@@ -1118,8 +1131,11 @@ impl AccountRequestProcessor {
));
}
let client = BackendClient::from_auth(self.config.chatgpt_base_url.clone(), &auth)
.map_err(|err| internal_error(format!("failed to construct backend client: {err}")))?;
let client = BackendClient::from_auth(
self.config.chatgpt_base_url.clone(),
&auth,
self.config.http_client_factory(),
);
match client
.send_add_credits_nudge_email(Self::backend_credit_type(params.credit_type))
@@ -109,8 +109,11 @@ impl AccountRequestProcessor {
));
}
BackendClient::from_auth(self.config.chatgpt_base_url.clone(), &auth)
.map_err(|err| internal_error(format!("failed to construct backend client: {err}")))
Ok(BackendClient::from_auth(
self.config.chatgpt_base_url.clone(),
&auth,
self.config.http_client_factory(),
))
}
}