MCPcopy Create free account
hub / github.com/HFQR/xitca-web / try_encode

Method try_encode

http-encoding/src/coding.rs:78–97  ·  view source on GitHub ↗

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 `Conten

(mut self, response: Response<S>)

Source from the content-addressed store, hash-verified

76 /// modifying `Content-Encoding` or `Transfer-Encoding` headers after calling this method,
77 /// as inconsistent values may cause incorrect behavior in downstream clients.
78 pub fn try_encode<S>(mut self, response: Response<S>) -> Response<Coder<S, FeaturedCode>>
79 where
80 S: Body,
81 S::Data: AsRef<[u8]> + 'static,
82 {
83 #[allow(unused_mut)]
84 let (mut parts, body) = response.into_parts();
85
86 if parts.headers.contains_key(&header::CONTENT_ENCODING)
87 || parts.status == StatusCode::SWITCHING_PROTOCOLS
88 || parts.status == StatusCode::NO_CONTENT
89 {
90 self = ContentEncoding::Identity;
91 }
92
93 self.update_header(&mut parts.headers, parts.version);
94
95 let body = self.encode_body(body);
96 Response::from_parts(parts, body)
97 }
98
99 /// Encode a [`Body`] with featured encoder
100 pub fn encode_body<S>(self, body: S) -> Coder<S, FeaturedCode>

Callers 2

compressedFunction · 0.80
callMethod · 0.80

Calls 3

update_headerMethod · 0.80
encode_bodyMethod · 0.80
into_partsMethod · 0.45

Tested by 1

compressedFunction · 0.64