Skip to content

fix(http): honor custom reqwest Client on WebSocket connect - #333

Open
SebTardif wants to merge 1 commit into
agentclientprotocol:mainfrom
SebTardif:fix/http-ws-honor-custom-client
Open

fix(http): honor custom reqwest Client on WebSocket connect#333
SebTardif wants to merge 1 commit into
agentclientprotocol:mainfrom
SebTardif:fix/http-ws-honor-custom-client

Conversation

@SebTardif

Copy link
Copy Markdown

HttpClient::with_client and with_endpoint_and_client take a configured reqwest::Client. HTTP/SSE uses that client. The WebSocket path discarded it and called async_tungstenite::tokio::connect_async with only the URL.

A caller that sets timeout, default headers, proxy, or custom TLS on the reqwest::Client therefore gets none of those settings on ws:// or wss://.

This has been true since the HTTP/WebSocket transport landed in #162.

Change

run_ws now performs the WebSocket handshake with the configured reqwest::Client (HTTP/1.1 upgrade), then wraps the upgraded stream in async-tungstenite. The client's timeout, default headers, proxy, and TLS apply to the connect.

Tests

  • websocket_with_client_sends_default_headers: public HttpClient::with_client on a local ws:// server. The handshake includes a default header set on the reqwest::Client.
  • websocket_with_client_honors_request_timeout: the same API against a listener that never accepts. A 200ms client timeout fails the handshake instead of hanging.

Red on unfixed main: the header is missing, and the timeout test hits the 1s outer timeout (Elapsed). Both pass after the change.

Does not overlap with #315 (server-side WebSocket frame limits), #328, #322, or #308.

run_ws discarded the configured Client and called
async-tungstenite connect_async with only the URL. HttpClient::with_client
and with_endpoint_and_client therefore ignored timeout, default headers,
proxy, and TLS on ws:// and wss://.

Perform the handshake with the reqwest Client, then wrap the upgraded
stream as a tungstenite WebSocket.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant