Skip to main content

Module compression

Module compression 

Source
Expand description

Gzip response compression middleware (feature compression)

Compresses text-like responses (text/*, JSON, JavaScript, XML, SVG) of at least Compression::min_size bytes when the client sends Accept-Encoding: gzip. Already encoded responses, HEAD requests and bodiless statuses are left alone. Vary: Accept-Encoding is added whenever a response could have been compressed, so caches keep both variants apart.

use ullun::compression::Compression;
use ullun::prelude::*;

App::new()
    .middleware(Compression::new())
    .get("/", |_req: Request| async { Ok(Response::text("hello ".repeat(500))) })
    .run("127.0.0.1:3000")
    .await
    .unwrap();

Structsยง

Compression
Gzip compression middleware