set content-type for html/css/js
This commit is contained in:
parent
48923386b3
commit
ef9629c3ea
1 changed files with 12 additions and 0 deletions
12
gitea.go
12
gitea.go
|
@ -102,11 +102,23 @@ func (m Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request, _ caddyhtt
|
||||||
return caddyhttp.Error(http.StatusNotFound, err)
|
return caddyhttp.Error(http.StatusNotFound, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetMimeType(w, r.URL.Path)
|
||||||
_, err = io.Copy(w, f)
|
_, err = io.Copy(w, f)
|
||||||
|
|
||||||
return err
|
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
|
// Interface guards
|
||||||
var (
|
var (
|
||||||
_ caddy.Provisioner = (*Middleware)(nil)
|
_ caddy.Provisioner = (*Middleware)(nil)
|
||||||
|
|
Reference in a new issue