Expand description
Response compression policy.
Without a policy the server keeps its long-standing behaviour: it
serves a precompressed sibling (.br, .zst, .gz) of a file when
the client accepts that encoding. Setting a CompressionPolicy
with ServerBuilder::compression_policy
adds the checks below, in order; the first that applies decides:
- the policy, or the matched route (
Route::compression), disables compression: the plain file is served; - the client accepts none of
br,zstdorgzip(q=0counts as not accepted); - the content type is not in
CompressionPolicy::compressible_types, which leaves already-compressed formats such as PNG or ZIP alone; - the file is smaller than
CompressionPolicy::min_size_bytes; - an accepted precompressed sibling exists: it is served;
- with the
compressionfeature andCompressionPolicy::dynamic_gzip, and noRangeheader, the body is gzip-compressed on the fly.
Each decision is counted; stats returns the counters and the
/metrics endpoint prints them.
§Examples
use http_handle::compression::CompressionPolicy;
use http_handle::Server;
let server = Server::builder()
.address("127.0.0.1:0")
.document_root(".")
.compression_policy(CompressionPolicy {
min_size_bytes: 512,
..CompressionPolicy::default()
})
.build()
.expect("server");
assert!(server.compression_policy().is_some());Structs§
- Compression
Policy - When and how responses are compressed.
- Compression
Stats - Counts of compression decisions since the process started.
Functions§
- stats
- Returns the compression decision counters.