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
impl ContentEncoding
pub const fn as_header_value(&self) -> HeaderValue
Sourcepub fn from_headers(headers: &HeaderMap) -> Self
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.
Sourcepub fn from_headers_with(headers: &HeaderMap, needle: &HeaderName) -> Self
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).
Sourcepub fn try_encode<S>(
self,
response: Response<S>,
) -> Response<Coder<S, FeaturedCode>>
pub fn try_encode<S>( self, response: Response<S>, ) -> Response<Coder<S, FeaturedCode>>
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.
Sourcepub fn encode_body<S>(self, body: S) -> Coder<S, FeaturedCode>
pub fn encode_body<S>(self, body: S) -> Coder<S, FeaturedCode>
Encode a Body with featured encoder
Sourcepub fn decode_body<S>(self, body: S) -> Coder<S, FeaturedCode>
pub fn decode_body<S>(self, body: S) -> Coder<S, FeaturedCode>
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
impl Clone for ContentEncoding
Source§fn clone(&self) -> ContentEncoding
fn clone(&self) -> ContentEncoding
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more