From 237c4f2f7874a5b107dfa0bace5675db3e71bd67 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Thu, 24 Jun 2010 14:37:55 +0200 Subject: [PATCH] lighttpd: Serve diff files as plain text. This allows browsers to view them directly, instead of opening an external editor for it. --- etc/lighttpd/scripts/create-mime.assign.pl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/etc/lighttpd/scripts/create-mime.assign.pl b/etc/lighttpd/scripts/create-mime.assign.pl index fbc4cf0..858600f 100755 --- a/etc/lighttpd/scripts/create-mime.assign.pl +++ b/etc/lighttpd/scripts/create-mime.assign.pl @@ -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() { 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"; -- 2.30.2