lighttpd: Serve diff files as plain text.
[matthijs/servers/drsnuggles.git] / etc / lighttpd / scripts / create-mime.assign.pl
index fbc4cf0af9207cdb811cfdf49fbd9be8d5f8fe0a..858600f07c3389a8d13ef7c5f13f3b86ec45560c 100755 (executable)
@@ -1,18 +1,27 @@
 #!/usr/bin/perl -w
 
 # This script is based on /usr/share/lighttpd/create-mime-assign.pl. This
-# script is changed to include a charset for text types.
+# script is changed to include a charset for text types. It is also changed to
+# serve some file types as text/plain, since browsers still don't have an
+# option to just view text/* in the browser, but need external programs for
+# anything but text/plain.
 
 use strict;
 open MIMETYPES, "/etc/mime.types" or exit;
 print "mimetype.assign = (\n";
 my %extensions;
+my %translate_types = (
+       "text/x-diff" => "text/plain",
+);
+
 while(<MIMETYPES>) {
   chomp;
   s/\#.*//;
   next if /^\w*$/;
   if(/^([a-z0-9\/+-.]+)\s+((?:[a-z0-9.+-]+[ ]?)+)$/) {
     my $mime = $1; my $exts = $2;
+    # Translate the mime type if needed
+    $mime = $translate_types{$mime} if exists $translate_types{$mime};
     # Append encoding for text formats
     if ($mime =~ /^text\//) {
       $mime .= "; charset=utf-8";