From: paul Date: Wed, 13 Apr 2016 11:11:05 +0000 (+0000) Subject: allow overriding file magic X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=ad0d9ced2d58a16fea9d75f517cd53fc5744cc73;p=cgilite allow overriding file magic svn path=/trunk/; revision=27 --- 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}"