Set content type to play video and hopefully audio in browser

master v0.6
bel 2020-04-11 01:41:29 +00:00
parent 334b64ca6d
commit 17e3e21e56
3 changed files with 16 additions and 0 deletions

16
main.go
View File

@ -99,6 +99,7 @@ func endpoints(foo http.HandlerFunc) http.HandlerFunc {
fmt.Fprintln(w, err.Error())
}
} else {
setContentTypeIfMedia(w, r)
foo(w, r)
}
}
@ -201,3 +202,18 @@ func toRealPath(p string) string {
d := path.Join(fs.Get("d").GetString())
return path.Join(d, p)
}
func setContentTypeIfMedia(w http.ResponseWriter, r *http.Request) {
switch path.Ext(r.URL.Path) {
case ".mp4":
w.Header().Set("Content-Type", "video/mp4")
case ".webm":
w.Header().Set("Content-Type", "video/webm")
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")
}
}

0
public/DIR2/e.md Normal file → Executable file
View File

0
public/b.md Normal file → Executable file
View File