Skip to content

Commit

Permalink
[core] expand mimetype.assign builtin defaults
Browse files Browse the repository at this point in the history
expand mimetype.assign builtin defaults with common media types for web
  • Loading branch information
gstrauss committed Aug 12, 2023
1 parent 44d311b commit 8545036
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 8 deletions.
11 changes: 6 additions & 5 deletions doc/scripts/create-mime.conf.pl
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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
##
Expand Down
95 changes: 92 additions & 3 deletions src/configfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 8545036

Please sign in to comment.