import (
"embed"
- _ "embed"
"path"
"strings"
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() {
}
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
}