Rust

compression

Module

Response compression: choosing an algorithm from the client's Accept-Encoding header, and compressing bodies with it.

The algorithms and the negotiation are utopia-compression's; this module adds what Response::send() decides on top: the levels, and which content types are compressed.

Contents

use utopia_http::Compression;
Rust
pub struct Compression

Response compression settings of an application.

Also implements Default.
use utopia_http::Algorithm;
Rust
pub enum Algorithm

A compression algorithm a response can be encoded with.

use utopia_http::compression::compressible;
Rust
pub fn compressible(content_type: &str) -> bool

Whether responses of a content type are compressed: text, scripts, JSON, XML, fonts, SVG and similar. Parameters are ignored and the match is case-insensitive.

use utopia_http::compression::from_accept_encoding;
Rust
pub fn from_accept_encoding(accept: &str, supported: &[String]) -> Option<Algorithm>

The algorithm to compress with for an Accept-Encoding header: the accepted one with the highest q (header order on ties) among supported (every algorithm when empty).

none and identity can win, and mean no compression; None is also returned when nothing supported is accepted.