Add support for setting mime type headers for known extensions
This commit is contained in:
parent
90177a39bc
commit
4e4baa154c
6
main.go
6
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user