]> git.plutz.net Git - cgilite/commitdiff
allow overriding file magic
authorpaul <paul@plutz.net>
Wed, 13 Apr 2016 11:11:05 +0000 (11:11 +0000)
committerpaul <paul@plutz.net>
Wed, 13 Apr 2016 11:11:05 +0000 (11:11 +0000)
svn path=/trunk/; revision=27

static.sh

index c86ed9f971b334a5f374f5feb9857d38765a0ab9..153cce0e7428f717a64d7fa1ac95103d77808a57 100755 (executable)
--- a/static.sh
+++ b/static.sh
 # along with shcgi.  If not, see <http://www.gnu.org/licenses/>. 
 
 
-unset length date file
+unset length date file suffix
 file="$_EXEC/static/$STATIC"
 date="$(stat -c %Y "$file")"
 
+# allow overriding magic file recognition
+# don't use this if `file` returns type correctly
+declare -A suffix
+suffix[css]="text/css"
+
 if [ -x "$file" -o \! -r "$file" -o \! -f "$file" ]; then
   printf 'HTTP/1.1 403 Forbidden\n\n'
 elif [ "$date" = "$HTTP_IF_NONE_MATCH" ]; then
   printf 'HTTP/1.1 304 Not Modified\n\n'
 else
   length="$(stat -c %s "$file")"
-  magic="$(file -bi "$file")"
+  magic="${suffix[${file##*.}]:-$(file -bi "$file")}"
 
   printf 'Etag: %s\r\n' "$date"
   printf 'Content-Type: %s\r\n' "${magic:-all/all}"