pub struct Encoder<B> { /* private fields */ }__compress only.Expand description
Response body that compresses chunks using a content encoding.
Implements MessageBody and reports BodySize::Stream when compression is enabled.
Buffered output is flushed when the underlying body returns Poll::Pending, and the
compressed stream is finalized when the body ends.
See Encoder::response for conditions that skip compression and the
module-level docs for supported encodings and runtime requirements.
Implementations§
Source§impl<B: MessageBody> Encoder<B>
impl<B: MessageBody> Encoder<B>
Sourcepub fn response(
encoding: ContentEncoding,
head: &mut ResponseHead,
body: B,
) -> Self
pub fn response( encoding: ContentEncoding, head: &mut ResponseHead, body: B, ) -> Self
Constructs a response body encoder and updates the response head if compression is enabled.
Compression is skipped when:
- The body size is
BodySize::NoneorBodySize::Sized(0). - The response already has a
Content-Encodingheader. - The response status is 101 Switching Protocols, 204 No Content, or 206 Partial Content.
encodingisContentEncoding::Identityor its codec feature is disabled.
Otherwise, sets Content-Encoding, appends accept-encoding to Vary, and enables chunked
transfer encoding in the response head. Existing Content-Length headers are not removed.
The caller must select encoding; this method does not negotiate Accept-Encoding.