MCPcopy
hub / github.com/daptin/daptin / ShouldCompress

Function ShouldCompress

server/cache/utils.go:6–52  ·  view source on GitHub ↗

ShouldCompress determines if a file should be compressed based on its content type

(contentType string)

Source from the content-addressed store, hash-verified

4
5// ShouldCompress determines if a file should be compressed based on its content type
6func ShouldCompress(contentType string) bool {
7 compressibleTypes := []string{
8 "text/",
9 "application/javascript",
10 "application/json",
11 "application/xml",
12 "application/xhtml+xml",
13 "image/svg+xml",
14 "application/font-woff",
15 "application/font-woff2",
16 "application/vnd.ms-fontobject",
17 "application/x-font-ttf",
18 "font/opentype",
19 "application/octet-stream",
20 }
21
22 // Don't compress already compressed formats
23 alreadyCompressed := []string{
24 "image/jpeg",
25 "image/png",
26 "image/gif",
27 "image/webp",
28 "audio/",
29 "video/",
30 "application/zip",
31 "application/gzip",
32 "application/x-gzip",
33 "application/x-compressed",
34 "application/x-zip-compressed",
35 }
36
37 // Check if content is already compressed
38 for _, t := range alreadyCompressed {
39 if strings.Contains(contentType, t) {
40 return false
41 }
42 }
43
44 // Check if content is compressible
45 for _, t := range compressibleTypes {
46 if strings.Contains(contentType, t) {
47 return true
48 }
49 }
50
51 return false
52}

Callers 2

AssetRouteHandlerFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected