Skip to main content

WsClientConfig

Struct WsClientConfig 

Source
pub struct WsClientConfig { /* private fields */ }
Expand description

Configuration for a WebSocket client connection.

Store this value in SharedCfg and pass the resulting configuration to WsClient::new.

Implementations§

Source§

impl WsClientConfig

Source

pub fn new() -> WsClientConfig

Creates a WebSocket client configuration with default values.

Source

pub fn set_address(self, addr: SocketAddr) -> Self

Sets the server socket address.

This address is used instead of resolving the URI host name.

Source

pub fn set_protocols<U, V>(self, protos: U) -> Result<Self, HttpError>
where U: IntoIterator<Item = V>, V: AsRef<str>,

Sets the WebSocket subprotocols offered to the server.

This replaces the current Sec-WebSocket-Protocol header. An empty iterator removes the header.

§Errors

Returns HttpError if a protocol is not a valid HTTP token or the resulting list is not a valid HTTP header value.

Adds a cookie to the opening handshake.

Source

pub fn set_origin<V, E>(self, origin: V) -> Result<Self, HttpError>
where HeaderValue: TryFrom<V, Error = E>, HttpError: From<E>,

Sets the Origin header for the opening handshake.

Source

pub fn set_max_frame_size(self, size: usize) -> Self

Sets the maximum accepted frame payload size.

The default is 64 KiB.

Source

pub fn set_server_mode(self) -> Self

Configures the connection to use server-side masking rules.

By default, the client masks outgoing frames and expects unmasked incoming frames. Server mode reverses those rules.

Source

pub fn set_header<K, V>(self, key: K, value: V) -> Result<Self, HttpError>

Sets a header for the opening handshake.

This replaces any existing value with the same name.

Source

pub fn set_header_if_none<K, V>( self, key: K, value: V, ) -> Result<Self, HttpError>

Sets a handshake header if it is not already present.

Source

pub fn set_basic_auth( self, username: impl Display, password: Option<&str>, ) -> Result<Self, HttpError>

Sets the HTTP Basic authentication header.

Source

pub fn set_bearer_auth(self, token: impl Display) -> Result<Self, HttpError>

Sets the HTTP bearer authentication header.

Source

pub fn set_handshake_timeout(self, timeout: impl Into<Millis>) -> Self

Sets the opening-handshake timeout.

The timeout covers sending the upgrade request and receiving the response after a connection has been established. The default is 5 seconds. A zero duration disables the timeout.

Source

pub fn set_close_timeout(self, timeout: impl Into<Millis>) -> Self

Sets the closing-handshake timeout.

After sending a close frame, the client waits this long for the peer’s close response before shutting down the connection. The default is 5 seconds. A zero duration disables the timeout.

Trait Implementations§

Source§

impl Configuration for WsClientConfig

Source§

const NAME: &str = "WebSocket client configuration"

Human-readable configuration name used in diagnostics.
Source§

fn ctx(&self) -> &CfgContext

Returns the shared context associated with this value.
Source§

fn set_ctx(&mut self, ctx: CfgContext)

Associates this value with a shared configuration context.
Source§

impl Debug for WsClientConfig

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for WsClientConfig

Source§

fn default() -> Self

Returns the “default value” for a type. 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, 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.