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
impl WsClientConfig
Sourcepub fn new() -> WsClientConfig
pub fn new() -> WsClientConfig
Creates a WebSocket client configuration with default values.
Sourcepub fn set_address(self, addr: SocketAddr) -> Self
pub fn set_address(self, addr: SocketAddr) -> Self
Sets the server socket address.
This address is used instead of resolving the URI host name.
Sourcepub fn set_protocols<U, V>(self, protos: U) -> Result<Self, HttpError>
pub fn set_protocols<U, V>(self, protos: U) -> Result<Self, HttpError>
Adds a cookie to the opening handshake.
Sourcepub fn set_origin<V, E>(self, origin: V) -> Result<Self, HttpError>
pub fn set_origin<V, E>(self, origin: V) -> Result<Self, HttpError>
Sets the Origin header for the opening handshake.
Sourcepub fn set_max_frame_size(self, size: usize) -> Self
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().
Sourcepub fn set_max_message_size(self, size: usize) -> Self
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().
Sourcepub fn set_validate_utf8(self, enabled: bool) -> Self
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().
Sourcepub fn set_server_mode(self) -> Self
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.
Sourcepub fn set_deflate(self, cfg: DeflateConfig) -> Self
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)
);Sourcepub fn set_header<K, V>(self, key: K, value: V) -> Result<Self, HttpError>where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
pub fn set_header<K, V>(self, key: K, value: V) -> Result<Self, HttpError>where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
Sets a header for the opening handshake.
This replaces any existing value with the same name.
Sourcepub fn set_header_if_none<K, V>(
self,
key: K,
value: V,
) -> Result<Self, HttpError>where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
pub fn set_header_if_none<K, V>(
self,
key: K,
value: V,
) -> Result<Self, HttpError>where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
Sets a handshake header if it is not already present.
Sourcepub fn set_basic_auth(
self,
username: impl Display,
password: Option<&str>,
) -> Result<Self, HttpError>
pub fn set_basic_auth( self, username: impl Display, password: Option<&str>, ) -> Result<Self, HttpError>
Sets the HTTP Basic authentication header.
Sourcepub fn set_bearer_auth(self, token: impl Display) -> Result<Self, HttpError>
pub fn set_bearer_auth(self, token: impl Display) -> Result<Self, HttpError>
Sets the HTTP bearer authentication header.
Sourcepub fn set_handshake_timeout(self, timeout: impl Into<Millis>) -> Self
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.
Sourcepub fn set_close_timeout(self, timeout: impl Into<Millis>) -> Self
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.