Share WebSocket dial future code across connection paths (#63353)

## Why

Boxing the dial future inside the generic `connect_with_route` can duplicate
its generated polling code for different route future types.

## What changed

Construct the boxed future in the non-generic `WebSocketConnector::dial`
helper so connections that resolve a proxy route and direct loopback
connections share the same polling code.

GitOrigin-RevId: a413733ac7e61732d0577d17a2f67ebd890f3757
This commit is contained in:
Charlie Marsh
2026-11-23 15:12:35 +00:00
committed by copyberry
parent 4889e4123a
commit 7c116ba81f
+22 -10
View File
@@ -162,6 +162,25 @@ impl WebSocketConnector {
.await
}
// Build the boxed dial future here so proxy routes and callers share its poll code.
fn dial(
&self,
request: Request,
config: WebSocketConfig,
proxy_route: OutboundProxyRoute,
loopback_direct: bool,
) -> BoxFuture<'static, Result<(ConnectionInner, Response), WebSocketError>> {
dialer::connect(
request,
config,
self.tls_config.clone(),
proxy_route,
self.tcp_nodelay,
loopback_direct,
)
.boxed()
}
async fn connect_with_route(
&self,
mut request: Request,
@@ -188,16 +207,9 @@ impl WebSocketConnector {
request.headers_mut().insert(COOKIE, cookies);
}
let proxy_route = route.await.map_err(WebSocketError::Io)?;
let result = dialer::connect(
request,
config,
self.tls_config.clone(),
proxy_route,
self.tcp_nodelay,
loopback_direct,
)
.boxed()
.await;
let result = self
.dial(request, config, proxy_route, loopback_direct)
.await;
// Like HTTP responses, rejected upgrades can also refresh infrastructure cookies.
match &result {
Ok((_, response)) => self