X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=static.sh;h=bf109ed26959e708d6d675ba57d38e829da517da;hp=6e9ceb773788905a21f092db87d3691397ae42dd;hb=1a1d111199b770c092e1b16a7e03568d3d911b79;hpb=d942060d292c47fd9c97ca4d41c9718fd60ebe78 diff --git a/static.sh b/static.sh index 6e9ceb7..bf109ed 100755 --- a/static.sh +++ b/static.sh @@ -20,7 +20,7 @@ unset length date file suffix file="$1" -date="$(stat -c %Y "$file")" +date="$(stat -Lc %Y "$file")" # allow overriding magic file recognition # don't use this if `file` returns type correctly @@ -35,13 +35,13 @@ if printf '%s' "${HTTP_RANGE}" |grep -qE '^bytes=[0-9]+-[0-9]*\r?$'; then _bend="${_range#*-}" fi -if [ -x "$file" -o \! -r "$file" -o \! -f "$file" ]; then +if ! [ -f "$file" ] || [ -x "$file" ] || ! grep -qm1 '' "$file" ; then printf 'Status:403 Forbidden\r\n\r\n' elif [ "$date" = "$cachedate" ]; then printf 'Status:304 Not Modified\r\n' printf 'Last-Modified: %s\r\n\r\n' "$(date -Rd "@$date")" elif [ "$_bstart" -gt 0 ] ; then - length="$(stat -c %s "$file")" + length="$(stat -Lc %s "$file")" magic="${suffix[${file##*.}]:-$(file -bi "$file")}" printf 'Status:206 Partial Content\r\n' @@ -53,7 +53,7 @@ elif [ "$_bstart" -gt 0 ] ; then tail -c+"$(($_bstart + 1))" "$file" else - length="$(stat -c %s "$file")" + length="$(stat -Lc %s "$file")" magic="${suffix[${file##*.}]:-$(file -bi "$file")}" printf 'Accept-Ranges: bytes\r\n'