diff --git a/middleware/compress.go b/middleware/compress.go index 7ba95fd5..a1baa57e 100644 --- a/middleware/compress.go +++ b/middleware/compress.go @@ -15,13 +15,11 @@ import ( ) var defaultCompressibleContentTypes = []string{ - "text/html", - "text/css", - "text/plain", - "text/javascript", + "text/*", "application/javascript", "application/x-javascript", "application/json", + "application/xml", "application/atom+xml", "application/rss+xml", "image/svg+xml", @@ -66,19 +64,18 @@ func NewCompressor(level int, types ...string) *Compressor { // provided, use the default list. allowedTypes := make(map[string]struct{}) allowedWildcards := make(map[string]struct{}) - if len(types) > 0 { - for _, t := range types { - if strings.Contains(strings.TrimSuffix(t, "/*"), "*") { - panic(fmt.Sprintf("middleware/compress: Unsupported content-type wildcard pattern '%s'. Only '/*' supported", t)) - } - if strings.HasSuffix(t, "/*") { - allowedWildcards[strings.TrimSuffix(t, "/*")] = struct{}{} - } else { - allowedTypes[t] = struct{}{} - } + + if len(types) == 0 { + types = defaultCompressibleContentTypes + } + + for _, t := range types { + if strings.Contains(strings.TrimSuffix(t, "/*"), "*") { + panic(fmt.Sprintf("middleware/compress: Unsupported content-type wildcard pattern '%s'. Only '/*' supported", t)) } - } else { - for _, t := range defaultCompressibleContentTypes { + if strings.HasSuffix(t, "/*") { + allowedWildcards[strings.TrimSuffix(t, "/*")] = struct{}{} + } else { allowedTypes[t] = struct{}{} } } diff --git a/middleware/compress_test.go b/middleware/compress_test.go index 992f1d40..2fd35b04 100644 --- a/middleware/compress_test.go +++ b/middleware/compress_test.go @@ -140,7 +140,8 @@ func TestCompressorWildcards(t *testing.T) { }{ { name: "defaults", - typesCount: 10, + typesCount: 7, + wcCount: 1, }, { name: "no wildcard",