Compression
Rue supports Gzip and Brotli compression with automatic content negotiation.
Usage
// Auto-select best compression (prefers Brotli)
r.Use(rue.Compress())
// Gzip only
r.Use(rue.Gzip())
// Brotli only
r.Use(rue.Brotli())
How It Works
The compression middleware:
- Checks the
Accept-Encodingheader - Selects the best supported algorithm
- Compresses the response body
- Sets the
Content-Encodingheader
Benchmarks
| Algorithm | Time | Compression Ratio |
|---|---|---|
| Gzip | ~43µs | Good |
| Brotli | ~18µs | Better |