LC_ALL=C sort -u > mime.types
# build lighttpd.conf fragment
-awk '{ printf("\t\".%s\"%s=> \"%s\",\n", $2, (length($2) > 4 ? "\t" : "\t\t"), $1)}' \
+awk '{
+ ext = $2;
+ type = $1;
+ charset = "";
+ # add charset for "text/*" types
+ if (type ~ "text/") {
+ type = "\"" type "\" + mimetype_textcharsetheader"
+ } else {
+ type = "\"" type "\""
+ }
+
+ printf("\t\".%s\"%s=> %s,\n", ext, (length(ext) > 4 ? "\t" : "\t\t"), type);
+}' \
< mime.types | LC_ALL=C sort -r > mime.types.conf
# sanity check. there can't be more than one mime type mapping for same extension
# header
cat >> mime.types.conf <<EOF
+# charset used for "text/*" mimetypes
+# Apache's AddCharset equivalent. Leave empty to add no charset.
+# AddCharset "utf-8" would be "; charset=\"utf-8\""
+# See this post about what it affects:
+# http://lists.pld-linux.org/mailman/pipermail/pld-devel-en/2012-February/022499.html
+mimetype_textcharsetheader = ""
+#mimetype_textcharsetheader = "; charset=\"utf-8\""
+
# mimetype mapping
mimetype.assign = (
EOF
cat >> mime.types.conf <<EOF
)
EOF
+
+rm -f mime.types.conf.tmp