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
This commit is contained in:
ben zhang
2026-10-27 22:03:01 +00:00
committed by copyberry
parent 83747ccc71
commit e343a12d5c
4 changed files with 14 additions and 4 deletions
+10 -3
View File
@@ -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)
@@ -0,0 +1 @@
@@ -0,0 +1 @@
@@ -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(