From 854503631ddcc1d6636dce8e11d46111ba5e8bed Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Sat, 12 Aug 2023 13:27:48 -0400 Subject: [PATCH] [core] expand mimetype.assign builtin defaults expand mimetype.assign builtin defaults with common media types for web --- doc/scripts/create-mime.conf.pl | 11 ++-- src/configfile.c | 95 +++++++++++++++++++++++++++++++-- 2 files changed, 98 insertions(+), 8 deletions(-) diff --git a/doc/scripts/create-mime.conf.pl b/doc/scripts/create-mime.conf.pl index 72a0fcf7f..e6a44acd9 100755 --- a/doc/scripts/create-mime.conf.pl +++ b/doc/scripts/create-mime.conf.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl -w -# Based on create-mime.assign.pl in debian lighttpd (1.4.x) package # Creates an example mime.conf from /etc/mime.types +# Based on create-mime.assign.pl originally in Debian lighttpd (1.4.x) package use strict; @@ -168,7 +168,7 @@ sub print_type { } # missing in /etc/mime.types; -# from http://www.iana.org/assignments/media-types/media-types.xhtml +# from https://www.iana.org/assignments/media-types/media-types.xhtml add(".dtd", "application/xml-dtd"); # RFC 9239 @@ -178,10 +178,10 @@ sub print_type { # other useful mappings my %useful = ( ".tar.gz" => "application/x-gtar-compressed", - ".gz" => "application/x-gzip", + ".gz" => "application/gzip", ".tbz" => "application/x-gtar-compressed", ".tar.bz2" => "application/x-gtar-compressed", - ".bz2" => "application/x-bzip", + ".bz2" => "application/x-bzip2", ".log" => "text/plain", ".conf" => "text/plain", ".spec" => "text/plain", @@ -217,7 +217,8 @@ sub print_type { ## ## Use extended attribute named in mimetype.xattr-name (default "Content-Type") -## to obtain mime type if possible +## to obtain mime type if possible. Note: this feature is generally not used +## and is not recommended for high-traffic sites. ## ## Disabled by default ## diff --git a/src/configfile.c b/src/configfile.c index f390dd29e..4bebae783 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -940,9 +940,25 @@ static int config_insert_srvconf(server *srv) { return rc; } +/* common media types for the web + * + * references: + * + * lighttpd doc/scripts/create-mime.pl + * https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types + * https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types + * https://docs.w3cub.com/http/basics_of_http/mime_types + * http://www.iana.org/assignments/media-types/media-types.xhtml + * https://salsa.debian.org/debian/media-types/-/blob/master/mime.types + * https://src.fedoraproject.org/rpms/mailcap/tree/rawhide + * https://pagure.io/mailcap/blob/master/f/mime.types + * + */ __attribute_cold__ static void config_mimetypes_default(array * const a) { static const char * const mimetypes_default[] = { + /*(order not important)*/ + ".html", "text/html" ,".htm", "text/html" ,".txt", "text/plain;charset=utf-8" @@ -951,19 +967,92 @@ static void config_mimetypes_default(array * const a) { ,".js", "text/javascript" ,".mjs", "text/javascript" ,".xml", "text/xml" - ,".jpg", "image/jpeg" + + ,".aac", "audio/aac" + ,".flac", "audio/flac" /* alt: "audio/x-flac" */ + ,".m4a", "audio/mp4" + ,".mp3", "audio/mpeg" + ,".oga", "audio/ogg" + ,".ogg", "audio/ogg" + ,".opus", "audio/opus" + ,".wav", "audio/x-wav" + ,".weba", "audio/webm" + ,".ogx", "application/ogg" + + ,".apng", "image/apng" /* alt: "image/vnd.mozilla.apng" */ + ,".avif", "image/avif" + ,".bmp", "image/bmp" + ,".gif", "image/gif" ,".jpeg", "image/jpeg" + ,".jpg", "image/jpeg" ,".png", "image/png" - ,".gif", "image/gif" ,".svg", "image/svg+xml" ,".svgz", "image/svg+xml" + ,".tiff", "image/tiff" + ,".webp", "image/webp" + + ,".avi", "video/x-msvideo" + ,".m4v", "video/mp4" + ,".mp4", "video/mp4" + ,".mpeg", "video/mpeg" + ,".ogv", "video/ogg" + ,".mov", "video/quicktime" + ,".qt", "video/quicktime" + ,".webm", "video/webm" + ,".json", "application/json" ,".dtd", "application/xml-dtd" ,".pdf", "application/pdf" + ,".xhtml", "application/xhtml+xml" + + ,".eot", "application/vnd.ms-fontobject" + ,".otf", "font/otf" + ,".sfnt", "font/sfnt" + ,".ttc", "font/collection" + ,".ttf", "font/ttf" ,".woff", "font/woff" ,".woff2", "font/woff2" + + ,".conf", "text/plain" + ,".log", "text/plain" + ,".csv", "text/csv" + ,".rtf", "text/rtf" + ,".ics", "text/calendar" ,".md", "text/markdown;charset=utf-8" - ,".ico", "image/x-icon" /* alt: "image/vnd.microsoft.icon" */ + ,".ico", "image/vnd.microsoft.icon" /* alt: "image/x-icon" */ + + /* "application/octet-stream" okay to trigger download for archives, + * but providing type (even if explicit "application/octet-stream") + * allows http_response_send_file() to send ETag and Last-Modified. + * (implicit "application/octet-stream" skips sending caching headers + * when type is not found in mimetype.assign (or xattr, if enabled)) */ + + ,".7z", "application/x-7z-compressed" + ,".bz2", "application/x-bzip2" + ,".gz", "application/gzip" /* alt: "application/x-gzip" */ + ,".rar", "application/vnd.rar" + ,".tar", "application/x-tar" + ,".tar.gz","application/x-gtar-compressed" + ,".tgz", "application/x-gtar-compressed" + ,".xz", "application/x-xz" + ,".zip", "application/zip" + ,".zst", "application/zstd" + + ,".bin", "application/octet-stream" + ,".class", "application/java-vm" + ,".dll", "application/x-msdos-program" + ,".exe", "application/x-msdos-program" + ,".img", "application/octet-stream" + ,".iso", "application/x-iso9660-image" + ,".jar", "application/java-archive" + ,".lha", "application/x-lha" + ,".lhz", "application/x-lzh" + ,".so", "application/octet-stream" + + ,".deb", "application/vnd.debian.binary-package" + ,".dmg", "application/x-apple-diskimage" + ,".rpm","application/x-redhat-package-manager"/*alt:"application/x-rpm"*/ + ,"README", "text/plain;charset=utf-8" #if 0