X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=file.sh;h=b6118f522d8b31d4fa0b19ec42226ab263b705cf;hp=084b7e643ee03ad3f55065e02d3bfa1d9865fa94;hb=e63a06bdd89bd5c3cb7232f3a5b6bf4a1f51493b;hpb=318867de22a49dc1e348cc1173ee4cdeb977d7b1 diff --git a/file.sh b/file.sh index 084b7e6..b6118f5 100755 --- a/file.sh +++ b/file.sh @@ -40,8 +40,8 @@ file_type(){ } FILE(){ - local file file_size file_date http_date cachedate range - file="$1" + local file file_size file_date http_date cachedate range mime + file="$1" mime="$2" if ! [ -f "$file" ]; then printf 'Content-Length: 0\r\nStatus: 404 Not Found\r\n\r\n' @@ -66,7 +66,7 @@ FILE(){ s;^[^ ]+ (...) ([0-9]) (..:..:..) ([0-9]{4})$;\4-\1-\2 \3;; s;Jan;01;; s;Feb;02;; s;Mar;03;; s;Apr;04;; s;May;05;; s;Jun;06;; s;Jul;07;; s;Aug;08;; s;Sep;09;; s;Oct;10;; s;Nov;11;; s;Dec;12;;' \ - | xargs -0 date +%s -ud 2>&- + | xargs -r0 date +%s -ud 2>&- )" range="$(HEADER Range |sed -nr 's;^bytes=([0-9]+-[0-9]*|-[0-9]+)$;\1;p;q;')" @@ -91,7 +91,7 @@ FILE(){ Status "200 OK" \ Accept-Ranges bytes \ Last-Modified "$http_date" \ - Content-Type $(file_type "$file") \ + Content-Type "${mime:-$(file_type "$file")}" \ Content-Length $file_size printf '\r\n' @@ -102,7 +102,7 @@ FILE(){ Status "206 Partial Content" \ Accept-Ranges bytes \ Last-Modified "$http_date" \ - Content-Type $(file_type "$file") \ + Content-Type "${mime:-$(file_type "$file")}" \ Content-Range "bytes ${range}/${file_size}" \ Content-Length "$((${range#*-} - ${range%-*} + 1))" printf '\r\n'