From 3f4e7615fb39e3bd33d4411ac87cb90d0f7c8b28 Mon Sep 17 00:00:00 2001 From: Arne Zeising Date: Tue, 23 Aug 2022 18:19:41 +0200 Subject: [PATCH] Add MIME type to served files --- static.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/static.go b/static.go index bb7cb9f..c66945c 100644 --- a/static.go +++ b/static.go @@ -98,6 +98,14 @@ func (h *uiAssetsHandler) serveFile(w http.ResponseWriter, path string) (code in } return http.StatusInternalServerError, err } + // Setting the MIME type for .js files manually to application/javascript as + // http.DetectContentType is using https://mimesniff.spec.whatwg.org/ which + // will not recognize application/javascript for security reasons. + if strings.HasSuffix(path, ".js") { + w.Header().Add("Content-Type", "application/javascript") + } else { + w.Header().Add("Content-Type", http.DetectContentType(bytes)) + } if _, err := w.Write(bytes); err != nil { return http.StatusInternalServerError, err