From 487972989392e148cc4a785eab561e1148184f62 Mon Sep 17 00:00:00 2001 From: Mohammad Hariri Date: Fri, 21 Feb 2025 19:06:28 +0100 Subject: [PATCH] fix: add correct content-type to their respective files --- main.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index b2acfbf..5d1452d 100644 --- a/main.go +++ b/main.go @@ -34,21 +34,23 @@ func SafeFileServer(root http.FileSystem) http.Handler { w.Header().Set("X-XSS-Protection", "1; mode=block") log.Println("assets handler", r.URL.Path) + log.Println(w.Header()) // Only allow specific file extensions if allowed := func(path string) bool { - allowedExts := map[string]bool{ - ".js": true, - ".css": true, - ".png": true, - ".webp": true, - ".jpg": true, - ".jpeg": true, - ".svg": true, - ".ico": true, + allowedExts := map[string]string{ + ".js": "text/javascript;charset=utf-8", + ".css": "text/css;charset=utf-8", + ".png": "image/png", + ".webp": "image/webp", + ".jpg": "image/jpeg", + ".jpeg": "image/jpeg", + ".svg": "image/svg+xml", + ".ico": "image/x-icon", } - for ext := range allowedExts { + for ext, contentType := range allowedExts { if strings.HasSuffix(path, ext) { + w.Header().Set("Content-Type", contentType) return true } }