From e343a12d5cb69ad3fc988fa2feed83b1a9610cbe Mon Sep 17 00:00:00 2001 From: ben zhang Date: Tue, 27 Oct 2026 21:47:20 +0000 Subject: [PATCH] Refactor HTTP client construction and request execution (#57575) ## What changed Construct the direct transport explicitly in `HttpClient::new` and reuse `without_request_logging` in `new_without_request_logging`. Bind awaited request results before matching them in transport execution and the Windows proxy retry path. GitOrigin-RevId: 58b2524491db80ff4d7a954868c1e030a1643a9d --- codex-rs/http-client/src/client.rs | 13 ++++++++++--- codex-rs/http-client/src/local_staging_routing.rs | 1 + .../http-client/src/local_staging_routing_tests.rs | 1 + .../src/route_aware_client_pool/execution.rs | 3 ++- 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 codex-rs/http-client/src/local_staging_routing.rs create mode 100644 codex-rs/http-client/src/local_staging_routing_tests.rs diff --git a/codex-rs/http-client/src/client.rs b/codex-rs/http-client/src/client.rs index c5c2e40bba..05a4d28889 100644 --- a/codex-rs/http-client/src/client.rs +++ b/codex-rs/http-client/src/client.rs @@ -50,12 +50,18 @@ impl std::fmt::Debug for TransportClient { impl HttpClient { pub fn new(inner: reqwest::Client) -> Self { - Self::from_parts(inner, RequestLogging::Enabled, HeaderMap::new()) + Self { + backend: HttpClientBackend::Direct(TransportClient { + inner, + request_logging: RequestLogging::Enabled, + default_headers: Arc::new(HeaderMap::new()), + }), + } } /// Suppresses diagnostics for endpoints whose URLs or headers may contain credentials. pub fn new_without_request_logging(inner: reqwest::Client) -> Self { - Self::from_parts(inner, RequestLogging::Disabled, HeaderMap::new()) + Self::new(inner).without_request_logging() } /// Suppresses URL and response-header diagnostics while preserving this client's routing. @@ -148,7 +154,8 @@ impl TransportClient { let method = request.method().clone(); let url = request.url().to_string(); - match self.execute_without_request_logging(request).await { + let result = self.execute_without_request_logging(request).await; + match result { Ok(response) => { self.log_response(&method, &url, &response); Ok(response) diff --git a/codex-rs/http-client/src/local_staging_routing.rs b/codex-rs/http-client/src/local_staging_routing.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/codex-rs/http-client/src/local_staging_routing.rs @@ -0,0 +1 @@ + diff --git a/codex-rs/http-client/src/local_staging_routing_tests.rs b/codex-rs/http-client/src/local_staging_routing_tests.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/codex-rs/http-client/src/local_staging_routing_tests.rs @@ -0,0 +1 @@ + diff --git a/codex-rs/http-client/src/route_aware_client_pool/execution.rs b/codex-rs/http-client/src/route_aware_client_pool/execution.rs index 1ddd4fe42d..cb5361914b 100644 --- a/codex-rs/http-client/src/route_aware_client_pool/execution.rs +++ b/codex-rs/http-client/src/route_aware_client_pool/execution.rs @@ -322,7 +322,8 @@ impl RouteAwareClientPool { let client = self.windows_proxy_client(current_route, selected_tls_backend, &pipe)?; set_remaining_timeout(&mut request, timeout_deadline)?; // Keep the listener alive through a possible TLS retry. - match client.execute_without_request_logging(request).await { + let result = client.execute_without_request_logging(request).await; + match result { Ok(response) => Ok(response), Err(error) => { self.retry_with_rustls(