From 17e3e21e56adeb4527a0bde1ef24b3c7e869dfab Mon Sep 17 00:00:00 2001 From: bel Date: Sat, 11 Apr 2020 01:41:29 +0000 Subject: [PATCH] Set content type to play video and hopefully audio in browser --- main.go | 16 ++++++++++++++++ public/DIR2/e.md | 0 public/b.md | 0 3 files changed, 16 insertions(+) mode change 100644 => 100755 public/DIR2/e.md mode change 100644 => 100755 public/b.md diff --git a/main.go b/main.go index 3f957e4..fe8ad62 100755 --- a/main.go +++ b/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") + } +} diff --git a/public/DIR2/e.md b/public/DIR2/e.md old mode 100644 new mode 100755 diff --git a/public/b.md b/public/b.md old mode 100644 new mode 100755