pub struct DeflateConfig { /* private fields */ }Expand description
Parameters of the permessage-deflate extension (RFC 7692).
On the client, this value is the extension offer, set it with
WsClientConfig::set_deflate(). The
parameters accepted by the server are available from
Codec::deflate() of the established connection.
On the server, this value holds the parameters the server accepts, see
DeflateConfig::negotiate(). The server uses at most the configured
window sizes, and asks the client to use the configured context takeover
and the client window size, if the client allows it.
A Codec applies the agreed parameters with
Codec::set_deflate().
Each connection allocates its own compressor and decompressor. With the default window size and compression level the compressor uses about 370KiB, and the decompressor about 46KiB.
Implementations§
Source§impl DeflateConfig
impl DeflateConfig
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a configuration with the default compression level, 32KiB windows and context takeover in both directions.
Sourcepub fn set_compression_level(self, level: u32) -> Self
pub fn set_compression_level(self, level: u32) -> Self
Sets the compression level of outgoing messages, from 0 (no compression) to 9 (best compression).
The default level is 6. Larger values are capped at 9.
Sourcepub fn set_client_no_context_takeover(self, value: bool) -> Self
pub fn set_client_no_context_takeover(self, value: bool) -> Self
Sets the client_no_context_takeover parameter.
The client resets its compressor after each message. It uses less memory between messages, but repeated content compresses worse.
Sourcepub fn set_server_no_context_takeover(self, value: bool) -> Self
pub fn set_server_no_context_takeover(self, value: bool) -> Self
Sets the server_no_context_takeover parameter.
The client asks the server to reset its compressor after each message. A server that does not agree fails the connection.
Sourcepub fn set_client_max_window_bits(self, bits: u8) -> Self
pub fn set_client_max_window_bits(self, bits: u8) -> Self
Sets the client_max_window_bits parameter, the base-2 logarithm of
the client’s LZ77 window size.
Values are clamped to the 8 to 15 range, the default window is 15 bits (32KiB). Smaller windows use less memory and compress worse. A client offers this parameter without a value by default, so the server can choose a smaller window.
Sourcepub fn set_server_max_window_bits(self, bits: u8) -> Self
pub fn set_server_max_window_bits(self, bits: u8) -> Self
Sets the server_max_window_bits parameter, the base-2 logarithm of
the server’s LZ77 window size.
Values are clamped to the 8 to 15 range. The client asks the server to use at most this window size, a server that does not agree fails the connection. By default, the server chooses.
Sourcepub fn compression_level(&self) -> u32
pub fn compression_level(&self) -> u32
Returns the compression level of outgoing messages.
Sourcepub fn client_no_context_takeover(&self) -> bool
pub fn client_no_context_takeover(&self) -> bool
Returns true if the client resets its compressor after each message.
Sourcepub fn server_no_context_takeover(&self) -> bool
pub fn server_no_context_takeover(&self) -> bool
Returns true if the server resets its compressor after each message.
Sourcepub fn client_max_window_bits(&self) -> Option<u8>
pub fn client_max_window_bits(&self) -> Option<u8>
Returns the client’s LZ77 window size, if it is limited.
Sourcepub fn server_max_window_bits(&self) -> Option<u8>
pub fn server_max_window_bits(&self) -> Option<u8>
Returns the server’s LZ77 window size, if it is limited.
Sourcepub fn negotiate(&self, headers: &HeaderMap) -> Option<(Self, HeaderValue)>
pub fn negotiate(&self, headers: &HeaderMap) -> Option<(Self, HeaderValue)>
Selects the client’s offer of the extension for a server.
The offers of the request’s Sec-WebSocket-Extensions headers are
checked in the client’s order of preference, the first valid offer is
accepted. Returns the agreed parameters and the
Sec-WebSocket-Extensions value of the handshake response. Apply the
parameters to the server’s codec with
Codec::set_deflate().
Returns None if the client does not offer the extension, or all
offers are invalid, the server then declines the extension.
use ntex::http::header::{HeaderMap, HeaderValue, SEC_WEBSOCKET_EXTENSIONS};
use ntex::ws::{self, DeflateConfig};
let mut headers = HeaderMap::new();
headers.insert(
SEC_WEBSOCKET_EXTENSIONS,
HeaderValue::from_static("permessage-deflate; client_max_window_bits"),
);
let mut codec = ws::Codec::new();
let cfg = DeflateConfig::new().set_server_no_context_takeover(true);
if let Some((agreed, response)) = cfg.negotiate(&headers) {
assert_eq!(response, "permessage-deflate; server_no_context_takeover");
codec = codec.set_deflate(agreed);
}Trait Implementations§
Source§impl Clone for DeflateConfig
impl Clone for DeflateConfig
Source§impl Debug for DeflateConfig
impl Debug for DeflateConfig
Source§impl Default for DeflateConfig
impl Default for DeflateConfig
impl Eq for DeflateConfig
Source§impl PartialEq for DeflateConfig
impl PartialEq for DeflateConfig
impl StructuralPartialEq for DeflateConfig
Auto Trait Implementations§
impl Freeze for DeflateConfig
impl RefUnwindSafe for DeflateConfig
impl Send for DeflateConfig
impl Sync for DeflateConfig
impl Unpin for DeflateConfig
impl UnsafeUnpin for DeflateConfig
impl UnwindSafe for DeflateConfig
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.