Improve handling of compression inclusion for objects (#19234)

This commit is contained in:
Dennis Marttinen 2024-03-11 11:55:34 +00:00 committed by GitHub
parent a25a8312d8
commit 6c964fede5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 5 deletions

View File

@ -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
}

View File

@ -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.