Merge branch 'master' of https://gogs.inhome.blapointe.com/local/simpleserve
commit
d706a2c4a3
46
main.go
46
main.go
|
|
@ -272,3 +272,49 @@ func toRealPath(p string) string {
|
||||||
d := path.Join(fs.Get("d").GetString())
|
d := path.Join(fs.Get("d").GetString())
|
||||||
return path.Join(d, p)
|
return path.Join(d, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setContentTypeIfMedia(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch strings.ToLower(path.Ext(r.URL.Path)) {
|
||||||
|
case ".mp4":
|
||||||
|
w.Header().Set("Content-Type", "video/mp4")
|
||||||
|
case ".mkv":
|
||||||
|
w.Header().Set("Content-Type", "video/x-matroska")
|
||||||
|
case ".mp3":
|
||||||
|
w.Header().Set("Content-Type", "audio/mpeg3")
|
||||||
|
case ".epub", ".mobi":
|
||||||
|
w.Header().Set("Content-Disposition", "attachment")
|
||||||
|
case ".jpg", ".jpeg":
|
||||||
|
w.Header().Set("Content-Type", "image/jpeg")
|
||||||
|
case ".gif":
|
||||||
|
w.Header().Set("Content-Type", "image/gif")
|
||||||
|
case ".png":
|
||||||
|
w.Header().Set("Content-Type", "image/png")
|
||||||
|
case ".ico":
|
||||||
|
w.Header().Set("Content-Type", "image/x-icon")
|
||||||
|
case ".svg":
|
||||||
|
w.Header().Set("Content-Type", "image/svg+xml")
|
||||||
|
case ".css":
|
||||||
|
w.Header().Set("Content-Type", "text/css")
|
||||||
|
case ".js":
|
||||||
|
w.Header().Set("Content-Type", "text/javascript")
|
||||||
|
case ".json":
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
case ".html", ".htm":
|
||||||
|
w.Header().Set("Content-Type", "text/html")
|
||||||
|
case ".pdf":
|
||||||
|
w.Header().Set("Content-Type", "application/pdf")
|
||||||
|
case ".webm":
|
||||||
|
w.Header().Set("Content-Type", "video/webm")
|
||||||
|
case ".weba":
|
||||||
|
w.Header().Set("Content-Type", "audio/webm")
|
||||||
|
case ".webp":
|
||||||
|
w.Header().Set("Content-Type", "image/webp")
|
||||||
|
case ".zip":
|
||||||
|
w.Header().Set("Content-Type", "application/zip")
|
||||||
|
case ".7z":
|
||||||
|
w.Header().Set("Content-Type", "application/x-7z-compressed")
|
||||||
|
case ".tar":
|
||||||
|
w.Header().Set("Content-Type", "application/x-tar")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>>>>>>> 66a35fcf10990bd0cd452a9eb7561b22581d250d
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue