X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=static.sh;fp=static.sh;h=c86ed9f971b334a5f374f5feb9857d38765a0ab9;hp=0000000000000000000000000000000000000000;hb=456423f02f12ac71d2d14e1abf959dafdc5eb041;hpb=397e40b92e591ae9066dcabb414d8097555beea8 diff --git a/static.sh b/static.sh new file mode 100755 index 0000000..c86ed9f --- /dev/null +++ b/static.sh @@ -0,0 +1,40 @@ +#!/bin/zsh + +# Copyright 2016 Paul Hänsch +# +# This file is part of shcgi. +# +# shcgi is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# shcgi is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with shcgi. If not, see . + + +unset length date file +file="$_EXEC/static/$STATIC" +date="$(stat -c %Y "$file")" + +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")" + + printf 'Etag: %s\r\n' "$date" + printf 'Content-Type: %s\r\n' "${magic:-all/all}" + printf 'Content-Length: %s\r\n' "$length" + printf '\r\n' + + cat "$file" +fi +