Crate rocket_async_compression

Source
Expand description

Gzip and Brotli response compression for Rocket

See the Compression and Compress types for further details.

§Usage

#[macro_use]
extern crate rocket;

use rocket_async_compression::Compression;

#[launch]
async fn rocket() -> _ {
    let server = rocket::build()
        .mount("/", routes![...]);

    if cfg!(debug_assertions) {
        server
    } else {
        server.attach(Compression::fairing())
    }
}

§Security Implications

In some cases, HTTP compression on a site served over HTTPS can make a web application vulnerable to attacks including BREACH. These risks should be evaluated in the context of your application before enabling compression.

Structs§

CachedCompression
Compresses all responses with Brotli or Gzip compression. Caches compressed response bodies in memory for selected file types/path suffixes, useful for compressing large compiled JS/CSS files, OTF font packs, etc. Note that all cached files are held in memory indefinitely.
Compress
Compresses responses with Brotli or Gzip compression using the async-compression crate.
Compression
Compresses all responses with Brotli or Gzip compression.

Enums§

Encoding
Level
Level of compression data should be compressed with.