pub struct CompressionPolicy {
pub encodings: Vec<String>,
pub min_size: usize,
}Expand description
The rules that decide which encoding an answer carries.
The policy holds no server state, so the same rules can be used by any server that answers with a compressed body.
Fields§
§encodings: Vec<String>The encodings that are offered, in the order they are preferred.
min_size: usizeThe smallest body that is worth compressing.
Implementations§
Source§impl CompressionPolicy
impl CompressionPolicy
Sourcepub fn pick(&self, accept_encoding: &str) -> Option<String>
pub fn pick(&self, accept_encoding: &str) -> Option<String>
The encoding the client asked for, when one of the offered encodings is accepted.
The offered encodings are tried in the order they are preferred, so the first one the client accepts is the one that is used.
§Arguments
&str- Theaccept-encodingheader of the request.
§Returns
Option<String>- The encoding to answer with, when the client accepts one of the offered encodings.
Sourcepub fn accepted(&self, accept_encoding: &str) -> Vec<String>
pub fn accepted(&self, accept_encoding: &str) -> Vec<String>
The encodings the client accepts, without the ones it refused.
An encoding that is refused with a quality of zero is dropped, and the tokens are read in the case the client wrote them in.
§Arguments
&str- Theaccept-encodingheader of the request.
§Returns
Vec<String>- The tokens the client accepts.
Sourcepub fn is_compressible(content_type: &str) -> bool
pub fn is_compressible(content_type: &str) -> bool
Whether a body of that content type is worth compressing.
A body that is already compressed is sent as it is, and the stream of events is never compressed. The rule does not depend on the encodings that are offered, so it is asked of the policy itself.
§Arguments
&str- The content type of the answer.
§Returns
bool- Whether the body may be compressed.