From ef9629c3ea9193637fb4e8de050b49212874892b Mon Sep 17 00:00:00 2001 From: Ascendise <rapperido@gmail.com> Date: Sat, 26 Oct 2024 15:53:15 +0200 Subject: [PATCH] set content-type for html/css/js --- gitea.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gitea.go b/gitea.go index 07fd631..0fc1eff 100644 --- a/gitea.go +++ b/gitea.go @@ -102,11 +102,23 @@ func (m Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request, _ caddyhtt return caddyhttp.Error(http.StatusNotFound, err) } + SetMimeType(w, r.URL.Path) _, err = io.Copy(w, f) return err } +// Sets the Content-Type for js, css and html so browsers actually load the stuff +func SetMimeType(w http.ResponseWriter, filePath string) { + if strings.HasSuffix(filePath, ".css") { + w.Header().Set("Content-Type", "text/css") + } else if strings.HasSuffix(filePath, ".js") { + w.Header().Set("Content-Type", "application/javascript") + } else if strings.HasSuffix(filePath, ".html") { + w.Header().Set("Content-Type", "text/html") + } +} + // Interface guards var ( _ caddy.Provisioner = (*Middleware)(nil)