]> git.plutz.net Git - cgilite/commitdiff
use proper cgi for response headers, switch cache machanism to timestamps
authorpaul <paul@plutz.net>
Wed, 9 Nov 2016 15:34:27 +0000 (15:34 +0000)
committerpaul <paul@plutz.net>
Wed, 9 Nov 2016 15:34:27 +0000 (15:34 +0000)
svn path=/trunk/; revision=41

server.sh
static.sh

index 4eb253ffe2696f5ac5be0b60be18d91da74b2511..a4229b252c90a409348c909e85df6f6027ff3384 100755 (executable)
--- a/server.sh
+++ b/server.sh
@@ -71,9 +71,10 @@ HTTP_format(){
   /^\r?$/!{H;n;bA}
   
   g
-  s;^(\r?\n)*;;
+  s;^(\r?\n)*;;;
+  s;([^\r])\n;\1\r\n;g;
   aConnection: close\r\n\r
-  /^HTTP\/[0-9]\.[0-9] [1-5][0-9][0-9] .*/bX
+  /^Status: *[1-5][0-9][0-9] .*/{s;^Status: *;HTTP/1.1 ;; bX}
   s;^(.+\n)?Location: .*$;HTTP/1.1 302 Found\r\n&;
   s;^(.+\n)?Content-Type: .*$;HTTP/1.1 200 OK\r\n&;
   
index 44c6556ed147a91e99218e2600bda85f09972c4b..ae8de6c3ed1dd1dad3b34f5af1dfd8c268feaec0 100755 (executable)
--- a/static.sh
+++ b/static.sh
@@ -27,16 +27,19 @@ date="$(stat -c %Y "$file")"
 declare -A suffix
 suffix[css]="text/css"
 
+[ -n "$HTTP_IF_MODIFIED_SINCE" ] && cachedate="$(date -d "$HTTP_IF_MODIFIED_SINCE" +%s)"
+
 if [ -x "$file" -o \! -r "$file" -o \! -f "$file" ]; then
-  printf 'HTTP/1.1 403 Forbidden\r\n\r\n'
-elif [ "$date" = "$HTTP_IF_NONE_MATCH" ]; then
-  printf 'HTTP/1.1 304 Not Modified\r\n'
-  printf 'Etag: %s\r\n\r\n' "$date"
+  printf 'Status:403 Forbidden\r\n\r\n'
+elif [ "$date" = "$cachedate" ]; then
+  debug "Delegating to client cache"
+  printf 'Status:304 Not Modified\r\n'
+  printf 'Last-Modified: %s\r\n\r\n' "$(date -Rd "@$date")"
 else
   length="$(stat -c %s "$file")"
   magic="${suffix[${file##*.}]:-$(file -bi "$file")}"
 
-  printf 'Etag: %s\r\n' "$date"
+  printf 'Last-Modified: %s\r\n' "$(date -Rd "@$date")"
   printf 'Content-Type: %s\r\n' "${magic:-all/all}"
   printf 'Content-Length: %s\r\n' "$length"
   printf '\r\n'