Struct jsonrpsee_ws_client::WsClientBuilder
source · 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 moresource§impl Debug for WsClientBuilder
impl Debug for WsClientBuilder
Auto Trait Implementations§
impl Freeze for WsClientBuilder
impl !RefUnwindSafe for WsClientBuilder
impl Send for WsClientBuilder
impl Sync for WsClientBuilder
impl Unpin for WsClientBuilder
impl !UnwindSafe for WsClientBuilder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)