Struct WebSocketBuilder

Source
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

Source

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.

Source

pub fn add_header(&mut self, header_name: &str, header_value: &str) -> &mut Self

Adds a header to be sent in the WebSocket handshake.

Source

pub fn remove_header(&mut self, header_name: &str) -> &mut Self

Removes a header which would be sent in the WebSocket handshake.

Source

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.

Source

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.

Source

pub fn tls_danger_accept_invalid_certs( &mut self, accept_invalid_certs: bool, ) -> &mut Self

Controls the use of certificate validation. Defaults to false.

Source

pub fn tls_danger_accept_invalid_hostnames( &mut self, accept_invalid_hostnames: bool, ) -> &mut Self

Controls the use of hostname verification. Defaults to false.

Source

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.

Source

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.

Source

pub fn tls_identity(&mut self, identity: TlsIdentity) -> &mut Self

Sets the identity to be used for client certificate authentication.

Source

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.

Source

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).

Source

pub fn tls_use_sni(&mut self, use_sni: bool) -> &mut Self

Controls the use of Server Name Indication (SNI). Defaults to true.

Trait Implementations§

Source§

impl Debug for WebSocketBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,