kitten: When guessing MIME types use a builtin list as a fallback, generated from the MIME type definitions available on the build system

This commit is contained in:
Kovid Goyal
2023-01-21 17:34:28 +05:30
parent 16f767de7e
commit b1934ce267
2 changed files with 22 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import (
"fmt"
"mime"
"path/filepath"
"strings"
)
var _ = fmt.Print
@@ -14,7 +15,14 @@ func GuessMimeType(filename string) string {
ext := filepath.Ext(filename)
mime_with_parameters := mime.TypeByExtension(ext)
if mime_with_parameters == "" {
return mime_with_parameters
only_once.Do(set_builtins)
mime_with_parameters = builtin_types_map[ext]
if mime_with_parameters == "" {
mime_with_parameters = builtin_types_map[strings.ToLower(ext)]
if mime_with_parameters == "" {
return ""
}
}
}
ans, _, err := mime.ParseMediaType(mime_with_parameters)
if err != nil {