feat(transport-ws): support custom TLS connector in WsConnect - #4149
Open
mehmetkr-31 wants to merge 2 commits into
Open
feat(transport-ws): support custom TLS connector in WsConnect#4149mehmetkr-31 wants to merge 2 commits into
mehmetkr-31 wants to merge 2 commits into
Conversation
mehmetkr-31
requested review from
DaniPopes,
grandizzy,
klkvr,
mattsse and
onbjerg
as code owners
August 16, 2026 19:18
`cargo check -p alloy-transport-ws --no-default-features` stopped compiling
with the custom-connector change:
error[E0425]: cannot find function `connect_async_tls_with_config`
in crate `tokio_tungstenite`
tokio-tungstenite exports the two pieces behind different gates:
#[cfg(any(native-tls, __rustls-tls, connect))] pub use tls::Connector;
#[cfg(any(native-tls, __rustls-tls))] pub async fn connect_async_tls_with_config
`connect` is on by default, so `Connector` — and with it the field, the
builders and the getter — resolves in every configuration. Only the connect
function disappears once no TLS backend is selected, which is exactly what
`--no-default-features` does here.
Selects the plain `connect_async_with_config` in that case. There is no TLS
to configure without a backend, so nothing is lost: the connector is only
reachable through a feature that also brings the TLS-aware entry point.
This lane is not hypothetical — CI reaches it through the `feature-checks`
job, which runs `cargo hack check --feature-powerset --depth 1` over the
workspace and therefore builds this crate with no features at all.
Verified on x86_64 Linux and aarch64 macOS: `--no-default-features` fails
before this commit and builds after it; default and `--all-features` build
either way; `cargo hack check --feature-powerset --depth 1` passes for
alloy-transport-ws; `cargo clippy --all-targets --all-features` reports
nothing; tests pass; `cargo +nightly fmt --all --check` is clean. The one
remaining warning in the powerset run (`extern crate rustls is unused`, on
`rustls-tls` without a crypto provider) is present on the base branch too.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Closes #3790.
Currently,
alloy-transport-wsconnects usingtokio-tungstenite's default connector configuration without exposing a hook for callers to supply a customConnector(such asnative-tls, system certificate stores, or custom root CAs). Whilealloy-transport-httpcan be configured with system/native TLS certificates, WebSocket connections against endpoints with non-WebPKI or enterprise certificates fail withUnknownIssuer.Solution
connector: Option<Connector>field toWsConnectwith builder methods.with_connector(connector)and.with_connector_opt(connector).Connectorfromalloy-transport-wson non-WASM targets.tokio_tungstenite::connect_async_tls_with_config(req, self.config, false, self.connector.clone())so custom connectors (e.g.Connector::NativeTlsorConnector::Rustlswith customClientConfig) are used when provided.fmt::DebugforWsConnectto gracefully handleConnectornot implementingDebug.PR Checklist