8. Compression¶
The compression() opt-in contract:
- Attaches
Accept-Encoding: gzip, deflateto the request (not attached before opt-in). - Transparently decompresses a
Content-Encoding: gzip | deflateresponse, and removes thecontent-encoding(and related length) header from the response map after decompressing. The user sees the body as if there was no compression. - deflate accepts both the zlib-wrapped and raw forms (detected by leading byte).
- Also enforces
maxResponseBodySizeon the size after decompression (compression-bomb defense). Exceeding it isCapacityExceeded. - A corrupted compressed body is
ProtocolError. - Decompression doesn't apply to streaming download — the sink receives the raw (compressed) bytes (Chapter 4 §4.4).
- Language mapping: cpp Boost.Beast zlib (parses the gzip header
itself, doesn't verify the CRC32 trailer), dotnet
System.IO.Compression(nativeAutomaticDecompressionturned off), javajava.util.zip, nodenode:zlib.