Does mod_deflate skip gzip compression for responses smaller than DeflateBufferSize?
0 reputation · 30 Aug 2026, 00:28 UTC
0 reputation · 30 Aug 2026, 00:28 UTC
Apache HTTP Server's mod_deflate controls gzip output through directives such as DeflateCompressionLevel and DeflateBufferSize, with compression normally enabled per MIME type via AddOutputFilterByType. The configuration goal is to serve gzipped application/octet-stream downloads with a consistent Content-Encoding: gzip header, a type that standard examples tend to leave out of the filter list.
What is unclear is how the filter treats a response whose body is smaller than the DeflateBufferSize value, the directive that sets the fragment size handed to zlib. It is not obvious from the directive descriptions whether such small payloads are compressed at all, whether the Content-Encoding header can differ between small and large responses of the same type, or whether the behavior changed between the 2.4 series and later releases. That makes it hard to predict what a client receives for a small binary download.
DeflateBufferSize, or pass them through uncompressed?Content-Encoding: gzip for small application/octet-stream responses on Apache 2.4?35275 reputation · 30 Aug 2026, 12:04 UTC
No, mod_deflate does not skip compression for responses smaller than the DeflateBufferSize. The DeflateBufferSize directive controls the size of the internal buffer used by the zlib library to process fragments of data; it is not a minimum size threshold for triggering compression.
If a response is processed by the deflate filter, it will be compressed and the Content-Encoding: gzip header will be applied, regardless of whether the payload is 10 bytes or 10 megabytes. This behavior is consistent across the Apache 2.4 series and previous 2.2.x releases.
Because application/octet-stream is often excluded from default compression lists to avoid double-compressing binary files, you must explicitly instruct Apache to filter this MIME type. To ensure small binary responses are consistently gzipped, use the following configuration:
# Enable compression for binary streams
AddOutputFilterByType DEFLATE application/octet-stream
# Optional: Ensure the buffer is tuned for your environment
DeflateBufferSize 8192Alternatively, if you only want this behavior for a specific path, use a <Location> block with SetOutputFilter DEFLATE.
To verify that small payloads are being compressed, you can use curl to inspect the headers of a file smaller than your configured DeflateBufferSize:
curl -I http://your-server/small-file.binContent-Encoding: gzip.curl http://your-server/small-file.bin | gunzip -tIf you find that small responses are still not being compressed despite the above settings, check for these common overrides:
no-gzip environment variables are being set for specific User-Agents..gz files directly via mod_rewrite, the deflate filter may be bypassed.Missing Diagnostic Detail: Are you using mod_rewrite or mod_headers to manually manipulate the Content-Encoding header elsewhere in your configuration?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.