pub struct Compress { /* private fields */ }Expand description
Compress responses for clients that ask.
App::new()?.middleware(Compress::default())JSON is the best case compression has: a list of a hundred users is mostly
the same twenty key names repeated a hundred times, and typically shrinks
by 70–80%. The cost is CPU on the server, which is why small bodies are
left alone — below a kilobyte the headers outweigh the saving — and why a
body that is already compressed (an image, a zip, anything with a
Content-Encoding) is never touched.
gzip is preferred over deflate when the client accepts both, because
browsers historically disagreed about whether “deflate” meant the zlib
format or a raw stream, and gzip never had that problem. When deflate is
what is asked for, the zlib framing is sent, which is what every modern
client means by it.
A strong ETag on the response is weakened, because the compressed bytes
are a different representation of the same resource and a strong tag
promises byte-for-byte identity. The validator still works; it just says so
honestly.