X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=static.sh;h=ae8de6c3ed1dd1dad3b34f5af1dfd8c268feaec0;hp=e8de7d16dc727bdaf18170f59cf261862173b6dd;hb=0fd2545f286734b69363fdb492fbfc6727e6fb32;hpb=0678b538a6d0f56a629a8e4dd9ef6e7665b14208 diff --git a/static.sh b/static.sh index e8de7d1..ae8de6c 100755 --- a/static.sh +++ b/static.sh @@ -19,7 +19,7 @@ unset length date file suffix -file="$_EXEC/static/$STATIC" +file="$1" date="$(stat -c %Y "$file")" # allow overriding magic file recognition @@ -27,15 +27,19 @@ date="$(stat -c %Y "$file")" declare -A suffix suffix[css]="text/css" +[ -n "$HTTP_IF_MODIFIED_SINCE" ] && cachedate="$(date -d "$HTTP_IF_MODIFIED_SINCE" +%s)" + if [ -x "$file" -o \! -r "$file" -o \! -f "$file" ]; then - printf 'HTTP/1.1 403 Forbidden\r\n\r\n' -elif [ "$date" = "$HTTP_IF_NONE_MATCH" ]; then - printf 'HTTP/1.1 304 Not Modified\r\n\r\n' + printf 'Status:403 Forbidden\r\n\r\n' +elif [ "$date" = "$cachedate" ]; then + debug "Delegating to client cache" + printf 'Status:304 Not Modified\r\n' + printf 'Last-Modified: %s\r\n\r\n' "$(date -Rd "@$date")" else length="$(stat -c %s "$file")" magic="${suffix[${file##*.}]:-$(file -bi "$file")}" - printf 'Etag: %s\r\n' "$date" + printf 'Last-Modified: %s\r\n' "$(date -Rd "@$date")" printf 'Content-Type: %s\r\n' "${magic:-all/all}" printf 'Content-Length: %s\r\n' "$length" printf '\r\n'