From ad0d9ced2d58a16fea9d75f517cd53fc5744cc73 Mon Sep 17 00:00:00 2001 From: paul Date: Wed, 13 Apr 2016 11:11:05 +0000 Subject: [PATCH] allow overriding file magic svn path=/trunk/; revision=27 --- static.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/static.sh b/static.sh index c86ed9f..153cce0 100755 --- a/static.sh +++ b/static.sh @@ -18,17 +18,22 @@ # along with shcgi. If not, see . -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}" -- 2.39.2