X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=rc%2Fmime.go;h=9aea81e6a9aea56d5b3d2e6ba9f098218bb5b7f9;hb=42568e5415055789d7e59b2fce2c7e14de262c74;hp=0b8d532d8cbfdfa0b9c6be361c5db25904fba605;hpb=49812df8ccd798598b747ca8958b413067bbe540;p=godlighty.git diff --git a/rc/mime.go b/rc/mime.go index 0b8d532..9aea81e 100644 --- a/rc/mime.go +++ b/rc/mime.go @@ -14,39 +14,32 @@ const MIMEDir = "mime" var ( //go:embed mime mimes embed.FS - - CompressibleMIMEBundles = map[string]struct{}{ - "mail": struct{}{}, - "playlist": struct{}{}, - "subtitle": struct{}{}, - "text": struct{}{}, - "web": struct{}{}, - "xml": struct{}{}, - } - CompressibleMIMEExts = []string{ - ".dvi", - ".eps", - ".fb2", - ".meta4", - ".metalink", - ".ps", - } ) -func parseMIME(p string) map[string]string { +type MIMEEntry struct { + ext string + mediaType string + compressible bool +} + +func parseMIME(p string) []MIMEEntry { tsv, err := mimes.ReadFile(path.Join(MIMEDir, p)) if err != nil { panic(err) } - m := make(map[string]string) + entries := make([]MIMEEntry, 0) for _, line := range strings.Split(string(tsv), "\n") { if len(line) == 0 || line[0] == '#' { continue } - cols := strings.SplitN(line, "\t", 2) - m[cols[0]] = cols[1] + cols := strings.Split(line, "\t") + entry := MIMEEntry{ext: cols[0], mediaType: cols[1]} + if len(cols) > 2 && cols[2] == "c" { + entry.compressible = true + } + entries = append(entries, entry) } - return m + return entries } func init() { @@ -56,18 +49,11 @@ func init() { } for _, entry := range entries { bundle := entry.Name() - _, allCompressible := CompressibleMIMEBundles[bundle] - for ext, mediaType := range parseMIME(bundle) { - godlighty.ContentTypes[ext] = mediaType - if allCompressible { - godlighty.CompressibleContentTypes[mediaType] = struct{}{} + for _, e := range parseMIME(bundle) { + godlighty.ContentTypes[e.ext] = e.mediaType + if e.compressible { + godlighty.CompressibleContentTypes[e.mediaType] = struct{}{} } } } - CompressibleMIMEBundles = nil - for _, ext := range CompressibleMIMEExts { - mediaType := godlighty.ContentTypes[ext] - godlighty.CompressibleContentTypes[mediaType] = struct{}{} - } - CompressibleMIMEExts = nil }