X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=static.sh;h=153cce0e7428f717a64d7fa1ac95103d77808a57;hp=c86ed9f971b334a5f374f5feb9857d38765a0ab9;hb=1a1cad8bb3939064315ccf1e2605a43da94eb332;hpb=456423f02f12ac71d2d14e1abf959dafdc5eb041 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}"