pub struct WebSocketBuilder { /* private fields */ }
Expand description
A builder used to customize the WebSocket handshake.
Handshake headers as well as subprotocols can be added and removed.
Methods prefixed with tls_
allow for the customization of a secure
WebSocket connection.
let mut ws = WebSocket::builder()
.add_subprotocol("wamp")
.connect("wss://echo.websocket.org")
.await?;
Implementations§
Source§impl WebSocketBuilder
impl WebSocketBuilder
Sourcepub async fn connect(&mut self, url: &str) -> Result<WebSocket, WebSocketError>
pub async fn connect(&mut self, url: &str) -> Result<WebSocket, WebSocketError>
Builds a WebSocket
using this builder, then connects to a URL
(and performs the WebSocket handshake).
After calling this method, no more methods should be called on this builder.
Sourcepub fn add_header(&mut self, header_name: &str, header_value: &str) -> &mut Self
pub fn add_header(&mut self, header_name: &str, header_value: &str) -> &mut Self
Adds a header to be sent in the WebSocket handshake.
Sourcepub fn remove_header(&mut self, header_name: &str) -> &mut Self
pub fn remove_header(&mut self, header_name: &str) -> &mut Self
Removes a header which would be sent in the WebSocket handshake.
Sourcepub fn add_subprotocol(&mut self, subprotocol: &str) -> &mut Self
pub fn add_subprotocol(&mut self, subprotocol: &str) -> &mut Self
Adds a subprotocol to the list of subprotocols to be sent in the
WebSocket handshake. The server may select a subprotocol from this list.
If it does, the selected subprotocol can be found using the
WebSocket::accepted_subprotocol()
method.
Sourcepub fn remove_subprotocol(&mut self, subprotocol: &str) -> &mut Self
pub fn remove_subprotocol(&mut self, subprotocol: &str) -> &mut Self
Removes a subprotocol from the list of subprotocols that would be sent in the WebSocket handshake.
Sourcepub fn tls_danger_accept_invalid_certs(
&mut self,
accept_invalid_certs: bool,
) -> &mut Self
pub fn tls_danger_accept_invalid_certs( &mut self, accept_invalid_certs: bool, ) -> &mut Self
Controls the use of certificate validation. Defaults to false.
Sourcepub fn tls_danger_accept_invalid_hostnames(
&mut self,
accept_invalid_hostnames: bool,
) -> &mut Self
pub fn tls_danger_accept_invalid_hostnames( &mut self, accept_invalid_hostnames: bool, ) -> &mut Self
Controls the use of hostname verification. Defaults to false.
Sourcepub fn tls_add_root_certificate(&mut self, cert: TlsCertificate) -> &mut Self
pub fn tls_add_root_certificate(&mut self, cert: TlsCertificate) -> &mut Self
Adds a certificate to the set of roots that the connector will trust. The connector will use the system’s trust root by default. This method can be used to add to that set when communicating with servers not trusted by the system. Defaults to an empty set.
Sourcepub fn tls_disable_built_in_roots(&mut self, disable: bool) -> &mut Self
pub fn tls_disable_built_in_roots(&mut self, disable: bool) -> &mut Self
Controls the use of built-in system certificates during certificate validation. Defaults to false – built-in system certs will be used.
Sourcepub fn tls_identity(&mut self, identity: TlsIdentity) -> &mut Self
pub fn tls_identity(&mut self, identity: TlsIdentity) -> &mut Self
Sets the identity to be used for client certificate authentication.
Sourcepub fn tls_max_protocol_version(
&mut self,
protocol: Option<TlsProtocol>,
) -> &mut Self
pub fn tls_max_protocol_version( &mut self, protocol: Option<TlsProtocol>, ) -> &mut Self
Sets the maximum supported TLS protocol version. A value of None enables support for the newest protocols supported by the implementation. Defaults to None.
Sourcepub fn tls_min_protocol_version(
&mut self,
protocol: Option<TlsProtocol>,
) -> &mut Self
pub fn tls_min_protocol_version( &mut self, protocol: Option<TlsProtocol>, ) -> &mut Self
Sets the minimum supported TLS protocol version. A value of None enables support for the oldest protocols supported by the implementation. Defaults to Some(Protocol::Tlsv10).
Sourcepub fn tls_use_sni(&mut self, use_sni: bool) -> &mut Self
pub fn tls_use_sni(&mut self, use_sni: bool) -> &mut Self
Controls the use of Server Name Indication (SNI). Defaults to true.