]> git.plutz.net Git - cgilite/commitdiff
allow override of file type
authorPaul Hänsch <paul@plutz.net>
Sun, 22 Jul 2018 13:26:41 +0000 (15:26 +0200)
committerPaul Hänsch <paul@plutz.net>
Sun, 22 Jul 2018 13:26:41 +0000 (15:26 +0200)
file.sh

diff --git a/file.sh b/file.sh
index 82eefae0af0298b09a64261913947d0622752aba..b6118f522d8b31d4fa0b19ec42226ab263b705cf 100755 (executable)
--- 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'
@@ -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'