diff --git a/contenttype.go b/contenttype.go index 964a823..676f971 100755 --- a/contenttype.go +++ b/contenttype.go @@ -15,57 +15,174 @@ func SetContentTypeIfMedia(w http.ResponseWriter, r *http.Request) { k := "Content-Type" v := "" switch ext { - case ".mp4": - v = "video/mp4" case ".mkv": v = "video/x-matroska" - case ".mp3": - v = "audio/mpeg3" case ".epub", ".mobi": + v = "application/epub+zip" k = "Content-Disposition" v = "attachment" - case ".jpg", ".jpeg": - v = "image/jpeg" case ".md": v = "text/markdown" v = "text/html" - case ".gif": - v = "image/gif" - case ".png": - v = "image/png" case ".ico": v = "image/x-icon" - case ".svg": - v = "image/svg+xml" - case ".css": - v = "text/css" - case ".js": - v = "text/javascript" - case ".json": - v = "application/json" - case ".html", ".htm": - v = "text/html" case ".pdf": w.Header().Set("Content-Disposition", fmt.Sprintf("inline; filename=%q", path.Base(r.URL.Path))) v = "application/pdf" - case ".webm": - v = "video/webm" - case ".weba": - v = "audio/webm" - case ".webp": - v = "image/webp" - case ".zip": - v = "application/zip" - case ".7z": - v = "application/x-7z-compressed" - case ".tar": - v = "application/x-tar" case ".m4b": v = "application/octet-stream" - case ".xml", ".rss", ".feed", ".rdf": + case ".rss", ".feed", ".rdf": v = "application/rss+xml" + + case ".htm": + v = "text/html; charset=utf-8" + case ".html": + v = "text/html; charset=utf-8" + case ".jpeg": + v = "image/jpeg" + case ".jpg": + v = "image/jpeg" case ".wasm": v = "application/wasm" + + case ".aac": + v = "audio/aac" + case ".abw": + v = "application/x-abiword" + case ".arc": + v = "application/x-freearc" + case ".avif": + v = "image/avif" + case ".avi": + v = "video/x-msvideo" + case ".azw": + v = "application/vnd.amazon.ebook" + case ".bin": + v = "application/octet-stream" + case ".bmp": + v = "image/bmp" + case ".bz": + v = "application/x-bzip" + case ".bz2": + v = "application/x-bzip2" + case ".cda": + v = "application/x-cdf" + case ".csh": + v = "application/x-csh" + case ".css": + v = "text/css" + case ".csv": + v = "text/csv" + case ".doc": + v = "application/msword" + case ".docx": + v = "application/vnd.openxmlformats-officedocument.wordprocessingml.document" + case ".eot": + v = "application/vnd.ms-fontobject" + case ".gz": + v = "application/gzip" + case ".gif": + v = "image/gif" + case ".htm,": + v = ".html text/html" + case ".ics": + v = "text/calendar" + case ".jar": + v = "application/java-archive" + case ".jpeg,": + v = ".jpg image/jpeg" + case ".js": + v = "text/javascript (Specifications: HTML and RFC 9239)" + case ".json": + v = "application/json" + case ".jsonld": + v = "application/ld+json" + case ".mid,": + v = ".midi audio/midi, audio/x-midi" + case ".mjs": + v = "text/javascript" + case ".mp3": + v = "audio/mpeg" + case ".mp4": + v = "video/mp4" + case ".mpeg": + v = "video/mpeg" + case ".mpkg": + v = "application/vnd.apple.installer+xml" + case ".odp": + v = "application/vnd.oasis.opendocument.presentation" + case ".ods": + v = "application/vnd.oasis.opendocument.spreadsheet" + case ".odt": + v = "application/vnd.oasis.opendocument.text" + case ".oga": + v = "audio/ogg" + case ".ogv": + v = "video/ogg" + case ".ogx": + v = "application/ogg" + case ".opus": + v = "audio/opus" + case ".otf": + v = "font/otf" + case ".png": + v = "image/png" + case ".php": + v = "application/x-httpd-php" + case ".ppt": + v = "application/vnd.ms-powerpoint" + case ".pptx": + v = "application/vnd.openxmlformats-officedocument.presentationml.presentation" + case ".rar": + v = "application/vnd.rar" + case ".rtf": + v = "application/rtf" + case ".sh": + v = "application/x-sh" + case ".svg": + v = "image/svg+xml" + case ".tar": + v = "application/x-tar" + case ".tif,": + v = ".tiff image/tiff" + case ".ts": + v = "video/mp2t" + case ".ttf": + v = "font/ttf" + case ".txt": + v = "text/plain" + case ".vsd": + v = "application/vnd.visio" + case ".wav": + v = "audio/wav" + case ".weba": + v = "audio/webm" + case ".webm": + v = "video/webm" + case ".webp": + v = "image/webp" + case ".woff": + v = "font/woff" + case ".woff2": + v = "font/woff2" + case ".xhtml": + v = "application/xhtml+xml" + case ".xls": + v = "application/vnd.ms-excel" + case ".xlsx": + v = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" + case ".xml": + v = "application/xml" + case ".xul": + v = "application/vnd.mozilla.xul+xml" + case ".zip": + v = "application/zip" + case ".3gp": + v = "video/3gpp; audio/3gpp if it doesn't contain video" + case ".3g2": + v = "video/3gpp2; audio/3gpp2 if it doesn't contain video" + case ".7z": + v = "application/x-7z-compressed" default: return }