X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=static.sh;fp=static.sh;h=0000000000000000000000000000000000000000;hp=bf109ed26959e708d6d675ba57d38e829da517da;hb=3fdb8e7e2ed8fcf3129de33147d1dd3b4a204b21;hpb=c287482dc24988cabd48a085e6d752d12b489550 diff --git a/static.sh b/static.sh deleted file mode 100755 index bf109ed..0000000 --- a/static.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/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 suffix -file="$1" -date="$(stat -Lc %Y "$file")" - -# allow overriding magic file recognition -# don't use this if `file` returns type correctly -declare -A suffix -suffix[css]="text/css" - -[ -n "$HTTP_IF_MODIFIED_SINCE" ] && cachedate="$(date -d "$HTTP_IF_MODIFIED_SINCE" +%s)" - -if printf '%s' "${HTTP_RANGE}" |grep -qE '^bytes=[0-9]+-[0-9]*\r?$'; then - _range="${HTTP_RANGE#bytes=}" - _bstart="${_range%-*}" - _bend="${_range#*-}" -fi - -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 -Lc %s "$file")" - magic="${suffix[${file##*.}]:-$(file -bi "$file")}" - - printf 'Status:206 Partial Content\r\n' - printf 'Last-Modified: %s\r\n' "$(date -Rd "@$date")" - printf 'Content-Type: %s\r\n' "${magic:-all/all}" - printf 'Content-Range: bytes %i-%i/%i\r\n' $_bstart $(($length - 1)) $length |debug - printf 'Content-Length: %i\r\n' $(($length - $_bstart)) - printf '\r\n' - - tail -c+"$(($_bstart + 1))" "$file" -else - length="$(stat -Lc %s "$file")" - magic="${suffix[${file##*.}]:-$(file -bi "$file")}" - - printf 'Accept-Ranges: bytes\r\n' - printf 'Last-Modified: %s\r\n' "$(date -Rd "@$date")" - printf 'Content-Type: %s\r\n' "${magic:-all/all}" - printf 'Content-Length: %i\r\n' "$length" - printf '\r\n' - - cat "$file" -fi -