fix(mime): register application/manifest+json for .webmanifest (+ webp/avif); v1.7.1

Go's MIME table has no .webmanifest entry, so http.FileServer sniffed the PWA web
app manifest as text/plain. mime.AddExtensionType at package load makes TypeByExtension
authoritative. A correctness nit (the manifest spec parses by content and nosniff does
not reject manifests), but a PWA server should label its manifest correctly.
This commit is contained in:
2026-08-18 18:43:55 -06:00
parent b73b9ee022
commit d6665047d8
6 changed files with 62 additions and 13 deletions
+24
View File
@@ -0,0 +1,24 @@
package spa
import "mime"
// Go's built-in MIME table — and a container image without /etc/mime.types — has no
// entry for these extensions, so http.FileServer falls back to content sniffing and
// mislabels them. The one that matters for a PWA server is the web app manifest,
// sniffed as text/plain instead of application/manifest+json. Registering the types
// once at package load makes mime.TypeByExtension authoritative, so the correct
// Content-Type is sent and no sniffing fallback runs.
//
// This is a correctness nit, not a fix for a live break: the manifest spec parses by
// content (valid JSON) rather than declared type, so browsers accept it either way.
// A PWA-focused server should still label it correctly. .webp/.avif get the same
// treatment for the same reason.
func init() {
for ext, typ := range map[string]string{
".webmanifest": "application/manifest+json",
".webp": "image/webp",
".avif": "image/avif",
} {
_ = mime.AddExtensionType(ext, typ)
}
}