Skip to main content

ContentEncoding

Enum ContentEncoding 

Source
pub enum ContentEncoding {
    Br,
    Deflate,
    Gzip,
    Zstd,
    Identity,
}
Expand description

Represents a supported content encoding.

Variants§

§

Br

A format using the Brotli algorithm.

§

Deflate

A format using the zlib structure with deflate algorithm.

§

Gzip

Gzip algorithm.

§

Zstd

Zstandard algorithm.

§

Identity

Indicates no operation is done with encoding.

Implementations§

Source§

impl ContentEncoding

Source

pub const fn as_header_value(&self) -> HeaderValue

Source

pub fn from_headers(headers: &HeaderMap) -> Self

Negotiate content encoding from the accept-encoding header.

Returns the highest q-value encoding that is supported by enabled crate features. Returns [ContentEncoding::NoOp] if no supported encoding is found.

Source

pub fn from_headers_with(headers: &HeaderMap, needle: &HeaderName) -> Self

Negotiate content encoding from a caller-specified header name.

Same as from_headers but reads from needle instead of accept-encoding. Useful for protocols that use a different header for encoding negotiation (e.g. grpc-accept-encoding for gRPC).

Source

pub fn try_encode<S>( self, response: Response<S>, ) -> Response<Coder<S, FeaturedCode>>
where S: Body, S::Data: AsRef<[u8]> + 'static,

Encode a response body, updating response headers accordingly.

Skips encoding if the response already has a Content-Encoding header, or if the status is 101 Switching Protocols or 204 No Content.

§Headers

Sets Content-Encoding and removes Content-Length when compression is applied. For HTTP/1.1 responses, Transfer-Encoding: chunked is appended. Callers should avoid modifying Content-Encoding or Transfer-Encoding headers after calling this method, as inconsistent values may cause incorrect behavior in downstream clients.

Source

pub fn encode_body<S>(self, body: S) -> Coder<S, FeaturedCode>
where S: Body, S::Data: AsRef<[u8]> + 'static,

Encode a Body with featured encoder

Source

pub fn decode_body<S>(self, body: S) -> Coder<S, FeaturedCode>
where S: Body, S::Data: AsRef<[u8]> + 'static,

Decode a Body with featured decoder.

Symmetric to encode_body. Use this when decoding outside of an HTTP response context (e.g. gRPC request decompression) where the encoding is determined by a protocol-specific header rather than Content-Encoding.

Trait Implementations§

Source§

impl Clone for ContentEncoding

Source§

fn clone(&self) -> ContentEncoding

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 Copy for ContentEncoding

Source§

impl Debug for ContentEncoding

Source§

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

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

impl Default for ContentEncoding

Source§

fn default() -> ContentEncoding

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

impl Eq for ContentEncoding

Source§

impl PartialEq for ContentEncoding

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ContentEncoding

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

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

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.