From 7c116ba81f516cfd5de35ce9e10ac0c2783b6022 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 23 Nov 2026 14:10:42 +0000 Subject: [PATCH] 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 --- codex-rs/websocket-client/src/lib.rs | 32 +++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/codex-rs/websocket-client/src/lib.rs b/codex-rs/websocket-client/src/lib.rs index ee97e5a8e2..3be762b167 100644 --- a/codex-rs/websocket-client/src/lib.rs +++ b/codex-rs/websocket-client/src/lib.rs @@ -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