parent
334b64ca6d
commit
17e3e21e56
16
main.go
16
main.go
|
|
@ -99,6 +99,7 @@ func endpoints(foo http.HandlerFunc) http.HandlerFunc {
|
||||||
fmt.Fprintln(w, err.Error())
|
fmt.Fprintln(w, err.Error())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
setContentTypeIfMedia(w, r)
|
||||||
foo(w, r)
|
foo(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -201,3 +202,18 @@ 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 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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue