From 4e4baa154c88deab9f98e5f3a056f13b7fb66dca Mon Sep 17 00:00:00 2001 From: James Mills <1290234+prologic@users.noreply.github.com> Date: Sun, 20 Aug 2023 01:15:42 +1000 Subject: [PATCH] Add support for setting mime type headers for known extensions --- main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.go b/main.go index 5a835ba..eb4e0c5 100644 --- a/main.go +++ b/main.go @@ -5,8 +5,10 @@ import ( "fmt" "io" "log" + "mime" "net/http" "os" + "path" "strings" "git.mills.io/prologic/pages-server/gitea" @@ -41,6 +43,10 @@ func (h *GiteaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } + extension := path.Ext(r.URL.Path) + mimeType := mime.TypeByExtension(extension) + w.Header().Add("content-type", mimeType) + if _, err := io.Copy(w, f); err != nil { http.Error(w, "Internal Server Error", http.StatusInternalServerError) }