diff --git a/cmd/object-api-utils.go b/cmd/object-api-utils.go index d7724f3bb..9e7ef8ffe 100644 --- a/cmd/object-api-utils.go +++ b/cmd/object-api-utils.go @@ -577,22 +577,35 @@ func excludeForCompression(header http.Header, object string, cfg compress.Confi } // Filter compression includes. - exclude := len(cfg.Extensions) > 0 || len(cfg.MimeTypes) > 0 + if len(cfg.Extensions) == 0 && len(cfg.MimeTypes) == 0 { + // Nothing to filter, include everything. + return false + } + if len(cfg.Extensions) > 0 && hasStringSuffixInSlice(objStr, cfg.Extensions) { - exclude = false + // Matched an extension to compress, do not exclude. + return false } if len(cfg.MimeTypes) > 0 && hasPattern(cfg.MimeTypes, contentType) { - exclude = false + // Matched an MIME type to compress, do not exclude. + return false } - return exclude + + // Did not match any inclusion filters, exclude from compression. + return true } // Utility which returns if a string is present in the list. -// Comparison is case insensitive. +// Comparison is case insensitive. Explicit short-circuit if +// the list contains the wildcard "*". func hasStringSuffixInSlice(str string, list []string) bool { str = strings.ToLower(str) for _, v := range list { + if v == "*" { + return true + } + if strings.HasSuffix(str, strings.ToLower(v)) { return true } diff --git a/docs/compression/README.md b/docs/compression/README.md index 8cf9fa4bd..1a8500514 100644 --- a/docs/compression/README.md +++ b/docs/compression/README.md @@ -59,6 +59,14 @@ export MINIO_COMPRESSION_EXTENSIONS=".txt,.log,.csv,.json,.tar,.xml,.bin" export MINIO_COMPRESSION_MIME_TYPES="text/*,application/json,application/xml" ``` +> [!NOTE] +> To enable compression for all content when using environment variables, set either or both of the extensions and MIME types to `*` instead of an empty string: +> ```bash +> export MINIO_COMPRESSION_ENABLE="on" +> export MINIO_COMPRESSION_EXTENSIONS="*" +> export MINIO_COMPRESSION_MIME_TYPES="*" +> ``` + ### 3. Compression + Encryption Combining encryption and compression is not safe in all setups.