master v0.9
Bel LaPointe 2020-07-12 17:56:37 -06:00
parent 3c5f23d3ac
commit c4747039a0
1 changed files with 27 additions and 20 deletions

47
main.go
View File

@ -208,46 +208,53 @@ func setContentTypeIfMedia(w http.ResponseWriter, r *http.Request) {
if i := strings.LastIndex(ext, "."); i != -1 {
ext = ext[i:]
}
k := "Content-Type"
v := ""
switch ext {
case ".mp4":
w.Header().Set("Content-Type", "video/mp4")
v = "video/mp4"
case ".mkv":
w.Header().Set("Content-Type", "video/x-matroska")
v = "video/x-matroska"
case ".mp3":
w.Header().Set("Content-Type", "audio/mpeg3")
v = "audio/mpeg3"
case ".epub", ".mobi":
w.Header().Set("Content-Disposition", "attachment")
k = "Content-Disposition"
v = "attachment"
case ".jpg", ".jpeg":
w.Header().Set("Content-Type", "image/jpeg")
v = "image/jpeg"
case ".gif":
w.Header().Set("Content-Type", "image/gif")
v = "image/gif"
case ".png":
w.Header().Set("Content-Type", "image/png")
v = "image/png"
case ".ico":
w.Header().Set("Content-Type", "image/x-icon")
v = "image/x-icon"
case ".svg":
w.Header().Set("Content-Type", "image/svg+xml")
v = "image/svg+xml"
case ".css":
w.Header().Set("Content-Type", "text/css")
v = "text/css"
case ".js":
w.Header().Set("Content-Type", "text/javascript")
v = "text/javascript"
case ".json":
w.Header().Set("Content-Type", "application/json")
v = "application/json"
case ".html", ".htm":
w.Header().Set("Content-Type", "text/html")
v = "text/html"
case ".pdf":
w.Header().Set("Content-Type", "application/pdf")
w.Header().Set("Content-Disposition", fmt.Sprintf("inline; filename=%q", path.Base(r.URL.Path)))
v = "application/pdf"
case ".webm":
w.Header().Set("Content-Type", "video/webm")
v = "video/webm"
case ".weba":
w.Header().Set("Content-Type", "audio/webm")
v = "audio/webm"
case ".webp":
w.Header().Set("Content-Type", "image/webp")
v = "image/webp"
case ".zip":
w.Header().Set("Content-Type", "application/zip")
v = "application/zip"
case ".7z":
w.Header().Set("Content-Type", "application/x-7z-compressed")
v = "application/x-7z-compressed"
case ".tar":
w.Header().Set("Content-Type", "application/x-tar")
v = "application/x-tar"
default:
return
}
w.Header().Set(k, v)
}