Skip to main content

DeflateConfig

Struct DeflateConfig 

Source
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

Source

pub fn new() -> Self

Creates a configuration with the default compression level, 32KiB windows and context takeover in both directions.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn compression_level(&self) -> u32

Returns the compression level of outgoing messages.

Source

pub fn client_no_context_takeover(&self) -> bool

Returns true if the client resets its compressor after each message.

Source

pub fn server_no_context_takeover(&self) -> bool

Returns true if the server resets its compressor after each message.

Source

pub fn client_max_window_bits(&self) -> Option<u8>

Returns the client’s LZ77 window size, if it is limited.

Source

pub fn server_max_window_bits(&self) -> Option<u8>

Returns the server’s LZ77 window size, if it is limited.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DeflateConfig

Source§

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

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

impl Default for DeflateConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for DeflateConfig

Source§

impl PartialEq for DeflateConfig

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DeflateConfig

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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