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"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.mills.io/prologic/pages-server/gitea"
|
"git.mills.io/prologic/pages-server/gitea"
|
||||||
@ -41,6 +43,10 @@ func (h *GiteaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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 {
|
if _, err := io.Copy(w, f); err != nil {
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user