Set content type to play video and hopefully audio in browser
This commit is contained in:
16
main.go
16
main.go
@@ -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
0
public/DIR2/e.md
Normal file → Executable file
0
public/b.md
Normal file → Executable file
0
public/b.md
Normal file → Executable file
Reference in New Issue
Block a user