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