+#!/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 <http://www.gnu.org/licenses/>.
+
+
+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
+