1package helpers
2
3import "strings"
4
5var builtinTypesLower = map[string]string{
6	".css":  "text/css; charset=utf-8",
7	".gif":  "image/gif",
8	".htm":  "text/html; charset=utf-8",
9	".html": "text/html; charset=utf-8",
10	".jpeg": "image/jpeg",
11	".jpg":  "image/jpeg",
12	".js":   "text/javascript; charset=utf-8",
13	".json": "application/json",
14	".mjs":  "text/javascript; charset=utf-8",
15	".pdf":  "application/pdf",
16	".png":  "image/png",
17	".svg":  "image/svg+xml",
18	".wasm": "application/wasm",
19	".webp": "image/webp",
20	".xml":  "text/xml; charset=utf-8",
21}
22
23// This is used instead of Go's built-in "mime.TypeByExtension" function because
24// that function is broken on Windows: https://github.com/golang/go/issues/32350.
25func MimeTypeByExtension(ext string) string {
26	contentType := builtinTypesLower[ext]
27	if contentType == "" {
28		contentType = builtinTypesLower[strings.ToLower(ext)]
29	}
30	return contentType
31}
32