]> Sergey Matveev's repositories - godlighty.git/commitdiff
Built-in MIMEs compression capability
authorSergey Matveev <stargrave@stargrave.org>
Sun, 3 Oct 2021 21:12:07 +0000 (00:12 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 3 Oct 2021 21:17:28 +0000 (00:17 +0300)
rc/mime.go
rc/mime/doc
rc/mime/mail
rc/mime/playlist
rc/mime/sharing
rc/mime/subtitle
rc/mime/text
rc/mime/web
rc/mime/xml

index 0b8d532d8cbfdfa0b9c6be361c5db25904fba605..9aea81e6a9aea56d5b3d2e6ba9f098218bb5b7f9 100644 (file)
@@ -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
 }
index b9f8af517b1845fb2d5c9a18fd70d8c7fe2b8cd5..367fd1ea3120cddff49a70fc1c55e6372536a490 100644 (file)
@@ -2,9 +2,9 @@
 .cbz   application/vnd.comicbook+zip
 .chm   application/vnd.ms-htmlhelp
 .djvu  image/vnd.djvu
-.dvi   application/x-dvi
-.eps   application/postscript
+.dvi   application/x-dvi       c
+.eps   application/postscript  c
 .epub  application/epub+zip
-.fb2   application/x-fictionbook+xml
+.fb2   application/x-fictionbook+xml   c
 .pdf   application/pdf
-.ps    application/postscript
+.ps    application/postscript  c
index 475382c7c0b8ff47eae146dad2bd5bd9c62b4b82..6c1d114cc8435b38490f8e4c6f51a1f8e148d65a 100644 (file)
@@ -1,3 +1,3 @@
-.eml   message/rfc822
-.mbox  application/mbox
-.mht   message/rfc822
+.eml   message/rfc822  c
+.mbox  application/mbox        c
+.mht   message/rfc822  c
index 45da94d8ccea45179eaaab8a95108f84a2cf3876..189ab563bce22025b7c19365de9fe4c6301b82d8 100644 (file)
@@ -1,3 +1,3 @@
-.m3u   application/vnd.apple.mpegurl
-.m3u8  application/vnd.apple.mpegurl
-.xspf  application/xspf+xml
+.m3u   application/vnd.apple.mpegurl   c
+.m3u8  application/vnd.apple.mpegurl   c
+.xspf  application/xspf+xml    c
index 10ee81891aa1828cd8c734440c7d1da81c442566..89afc56e9ad07805eefc1f95b925897b6f0261d4 100644 (file)
@@ -1,4 +1,4 @@
 .iso   application/x-iso9660-image
-.meta4 application/metalink4+xml
-.metalink      application/metalink+xml
+.meta4 application/metalink4+xml       c
+.metalink      application/metalink+xml        c
 .torrent       application/x-bittorrent
index 5f1083785d61197d5dc771d27bbccad6658b1f61..3a3f6bae54745625d8a20f3e03908a3d4c5910c6 100644 (file)
@@ -1,3 +1,3 @@
-.ass   text/x-ssa
-.srt   application/x-subrip
-.ssa   text/x-ssa
+.ass   text/x-ssa      c
+.srt   application/x-subrip    c
+.ssa   text/x-ssa      c
index 6990162fe78770dd596af534d1411b790c25668b..b7013e5f933d30f55d299ba0c4dcafff4d53a636 100644 (file)
@@ -1,22 +1,22 @@
-.asc   text/plain
-.csv   text/csv
-.cue   text/plain
-.gmi   text/gemini; charset=utf-8
-.icf   text/calendar; charset=utf-8
-.info  text/info; charset=utf-8
-.json  application/json; charset=utf-8
-.ldif  text/plain; charset=utf-8
-.log   text/plain; charset=utf-8
-.md    text/markdown; charset=utf-8
-.pod   text/x-pod; charset=utf-8
-.readme        text/plain; charset=utf-8
-.rec   text/plain; charset=utf-8
-.sql   text/plain; charset=utf-8
-.tex   application/x-tex
-.txt   text/plain; charset=utf-8
-.url   text/uri-list; charset=utf-8
-.vcf   text/vcard; charset=utf-8
-.yaml  text/yaml; charset=utf-8
-.zone  text/dns; charset=utf-8
-ls-lR  text/plain; charset=utf-8
-README text/plain; charset=utf-8
+.asc   text/plain      c
+.csv   text/csv        c
+.cue   text/plain      c
+.gmi   text/gemini; charset=utf-8      c
+.icf   text/calendar; charset=utf-8    c
+.info  text/info; charset=utf-8        c
+.json  application/json; charset=utf-8 c
+.ldif  text/plain; charset=utf-8       c
+.log   text/plain; charset=utf-8       c
+.md    text/markdown; charset=utf-8    c
+.pod   text/x-pod; charset=utf-8       c
+.readme        text/plain; charset=utf-8       c
+.rec   text/plain; charset=utf-8       c
+.sql   text/plain; charset=utf-8       c
+.tex   application/x-tex       c
+.txt   text/plain; charset=utf-8       c
+.url   text/uri-list; charset=utf-8    c
+.vcf   text/vcard; charset=utf-8       c
+.yaml  text/yaml; charset=utf-8        c
+.zone  text/dns; charset=utf-8 c
+ls-lR  text/plain; charset=utf-8       c
+README text/plain; charset=utf-8       c
index 166f30e165012beaa2a2257a965f962e5f884ca8..4a9d9c50d8611f326e2d439f49159ec8cb1492a3 100644 (file)
@@ -1,7 +1,7 @@
-.css   text/css; charset=utf-8
-.dtd   application/xml-dtd
-.htm   text/html
-.html  text/html
-.js    application/javascript; charset=utf-8
+.css   text/css; charset=utf-8 c
+.dtd   application/xml-dtd     c
+.htm   text/html       c
+.html  text/html       c
+.js    application/javascript; charset=utf-8   c
 .wasm  application/wasm
-.xhtml application/xhtml+xml
+.xhtml application/xhtml+xml   c
index d81783eccd58d445abbfdf96ea859a75e245e447..7cbe99d20586ab89f97a78ecc63aca397fa725c0 100644 (file)
@@ -1,7 +1,7 @@
-.atom  application/atom+xml
-.dbk   application/docbook+xml
-.opml  application/xml
-.rss   application/rss+xml
-.xbel  application/xml
-.xml   application/xml
-.xmp   application/rdf+xml
+.atom  application/atom+xml    c
+.dbk   application/docbook+xml c
+.opml  application/xml c
+.rss   application/rss+xml     c
+.xbel  application/xml c
+.xml   application/xml c
+.xmp   application/rdf+xml     c