Add support for setting mime type headers for known extensions

This commit is contained in:
James Mills 2023-08-20 01:15:42 +10:00
parent 90177a39bc
commit 4e4baa154c
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6

View File

@ -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)
}