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. The total size of a fragmented message is limited separately, see WsClientConfig::set_max_message_size().

Source

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

Sets the maximum accepted payload size of an incoming message.

The limit applies to the total payload of all frames of a message. The default is 4 MiB, see Codec::max_message_size().

Source

pub fn set_validate_utf8(self, enabled: bool) -> Self

Enables or disables UTF-8 validation of incoming text messages.

Validation is enabled by default, see Codec::validate_utf8().

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_deflate(self, cfg: DeflateConfig) -> Self

Offers the permessage-deflate extension (RFC 7692) to the server.

If the server accepts the offer, text and binary messages are compressed in both directions. The server may decline it, then the messages are not compressed. The opening handshake fails if the server accepts the offer with parameters the client did not allow.

The extension is not offered by default.

use ntex::ws::{DeflateConfig, WsClientConfig};

let cfg = WsClientConfig::new().set_deflate(
    DeflateConfig::new().set_client_no_context_takeover(true)
);
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. Read more
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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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

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

§

fn vzip(self) -> V