pub struct WsClientBuilder { /* private fields */ }
Expand description
Builder for WsClient
.
§Examples
use jsonrpsee_ws_client::{WsClientBuilder, HeaderMap, HeaderValue};
#[tokio::main]
async fn main() {
// Build custom headers used during the handshake process.
let mut headers = HeaderMap::new();
headers.insert("Any-Header-You-Like", HeaderValue::from_static("42"));
// Build client
let client = WsClientBuilder::default()
.set_headers(headers)
.build("wss://localhost:443")
.await
.unwrap();
// use client....
}
Implementations§
Source§impl WsClientBuilder
impl WsClientBuilder
Sourcepub fn new() -> WsClientBuilder
pub fn new() -> WsClientBuilder
Create a new WebSocket client builder.
Sourcepub fn with_custom_cert_store(self, cfg: CustomCertStore) -> Self
pub fn with_custom_cert_store(self, cfg: CustomCertStore) -> Self
Force to use a custom certificate store.
§Optional
This requires the optional tls
feature.
§Example
use jsonrpsee_ws_client::{WsClientBuilder, CustomCertStore};
use rustls::{
client::danger::{self, HandshakeSignatureValid, ServerCertVerified},
pki_types::{CertificateDer, ServerName, UnixTime},
Error,
};
#[derive(Debug)]
struct NoCertificateVerification;
impl rustls::client::danger::ServerCertVerifier for NoCertificateVerification {
fn verify_server_cert(
&self,
_: &CertificateDer<'_>,
_: &[CertificateDer<'_>],
_: &ServerName<'_>,
_: &[u8],
_: UnixTime,
) -> Result<ServerCertVerified, Error> {
Ok(ServerCertVerified::assertion())
}
fn supported_verify_schemes(&self) -> Vec<rustls::SignatureScheme> {
vec![rustls::SignatureScheme::ECDSA_NISTP256_SHA256]
}
fn verify_tls12_signature(
&self,
_: &[u8],
_: &CertificateDer<'_>,
_: &rustls::DigitallySignedStruct,
) -> Result<rustls::client::danger::HandshakeSignatureValid, Error> {
Ok(HandshakeSignatureValid::assertion())
}
fn verify_tls13_signature(
&self,
_: &[u8],
_: &CertificateDer<'_>,
_: &rustls::DigitallySignedStruct,
) -> Result<HandshakeSignatureValid, Error> {
Ok(HandshakeSignatureValid::assertion())
}
}
let tls_cfg = CustomCertStore::builder()
.dangerous()
.with_custom_certificate_verifier(std::sync::Arc::new(NoCertificateVerification))
.with_no_client_auth();
// client builder with disabled certificate verification.
let client_builder = WsClientBuilder::new().with_custom_cert_store(tls_cfg);
Sourcepub fn max_request_size(self, size: u32) -> Self
pub fn max_request_size(self, size: u32) -> Self
See documentation WsTransportClientBuilder::max_request_size
(default is 10 MB).
Sourcepub fn max_response_size(self, size: u32) -> Self
pub fn max_response_size(self, size: u32) -> Self
See documentation WsTransportClientBuilder::max_response_size
(default is 10 MB).
Sourcepub fn request_timeout(self, timeout: Duration) -> Self
pub fn request_timeout(self, timeout: Duration) -> Self
See documentation ClientBuilder::request_timeout
(default is 60 seconds).
Sourcepub fn connection_timeout(self, timeout: Duration) -> Self
pub fn connection_timeout(self, timeout: Duration) -> Self
See documentation WsTransportClientBuilder::connection_timeout
(default is 10 seconds).
Sourcepub fn enable_ws_ping(self, cfg: PingConfig) -> Self
pub fn enable_ws_ping(self, cfg: PingConfig) -> Self
See documentation ClientBuilder::enable_ws_ping
(disabled by default).
Sourcepub fn disable_ws_ping(self) -> Self
pub fn disable_ws_ping(self) -> Self
See documentation ClientBuilder::disable_ws_ping
Sourcepub fn set_headers(self, headers: HeaderMap) -> Self
pub fn set_headers(self, headers: HeaderMap) -> Self
See documentation WsTransportClientBuilder::set_headers
(default is none).
Sourcepub fn max_concurrent_requests(self, max: usize) -> Self
pub fn max_concurrent_requests(self, max: usize) -> Self
See documentation ClientBuilder::max_concurrent_requests
(default is 256).
Sourcepub fn max_buffer_capacity_per_subscription(self, max: usize) -> Self
pub fn max_buffer_capacity_per_subscription(self, max: usize) -> Self
See documentation ClientBuilder::max_buffer_capacity_per_subscription
(default is 1024).
Sourcepub fn max_redirections(self, redirect: usize) -> Self
pub fn max_redirections(self, redirect: usize) -> Self
See documentation WsTransportClientBuilder::max_redirections
(default is 5).
Sourcepub fn id_format(self, kind: IdKind) -> Self
pub fn id_format(self, kind: IdKind) -> Self
See documentation for ClientBuilder::id_format
(default is Number).
Sourcepub fn set_max_logging_length(self, max: u32) -> Self
pub fn set_max_logging_length(self, max: u32) -> Self
Set maximum length for logging calls and responses.
Logs bigger than this limit will be truncated.
Sourcepub fn set_tcp_no_delay(self, no_delay: bool) -> Self
pub fn set_tcp_no_delay(self, no_delay: bool) -> Self
See documentation ClientBuilder::set_tcp_no_delay
(default is true).
Sourcepub fn build_with_transport<S, R>(self, sender: S, receiver: R) -> WsClient
pub fn build_with_transport<S, R>(self, sender: S, receiver: R) -> WsClient
Build the WsClient
with specified TransportSenderT
TransportReceiverT
parameters
§Panics
Panics if being called outside of tokio
runtime context.
Sourcepub async fn build_with_stream<T>(
self,
url: impl AsRef<str>,
data_stream: T,
) -> Result<WsClient, Error>
pub async fn build_with_stream<T>( self, url: impl AsRef<str>, data_stream: T, ) -> Result<WsClient, Error>
Build the WsClient
with specified data stream, using WsTransportClientBuilder::build_with_stream
.
§Panics
Panics if being called outside of tokio
runtime context.
Sourcepub async fn build(self, url: impl AsRef<str>) -> Result<WsClient, Error>
pub async fn build(self, url: impl AsRef<str>) -> Result<WsClient, Error>
Build the WsClient
with specified URL to connect to, using the default
WsTransportClientBuilder::build_with_stream
, therefore with the default TCP as transport layer.
§Panics
Panics if being called outside of tokio
runtime context.
Trait Implementations§
Source§impl Clone for WsClientBuilder
impl Clone for WsClientBuilder
Source§fn clone(&self) -> WsClientBuilder
fn clone(&self) -> WsClientBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more