]> git.plutz.net Git - clickslide/commitdiff
shorter version of webserver response builder
authorPaul Hänsch <paul@plutz.net>
Wed, 4 Jul 2018 22:05:58 +0000 (00:05 +0200)
committerPaul Hänsch <paul@plutz.net>
Wed, 4 Jul 2018 22:05:58 +0000 (00:05 +0200)
cgilite.sh

index 79982884dfffffb91e83c6f8392c72e5becdaa1a..3292e031a81c6672baa47f569108f17caaf6e101 100755 (executable)
@@ -81,22 +81,16 @@ if [ -z "$REQUEST_METHOD" -a -z "$SERVER_PROTOCOL" ]; then
     # Without Content-Length header, connection will terminate after
     # script.
 
     # Without Content-Length header, connection will terminate after
     # script.
 
-    cgilite_status='200 OK'; cgilite_response=''; cgilite_cl='';
+    cgilite_status='200 OK'; cgilite_response=''; cgilite_cl="Connection: close${CR}";
     . "$0" |sed '1{s;^Status: ;HTTP/1.1 ;; t; s;^;HTTP/1.1 200 OK\r\n;;}' \
     | while read -r l; do case $l in
       Status:*) cgilite_status="${l#Status: }";;
     . "$0" |sed '1{s;^Status: ;HTTP/1.1 ;; t; s;^;HTTP/1.1 200 OK\r\n;;}' \
     | while read -r l; do case $l in
       Status:*) cgilite_status="${l#Status: }";;
-      Content-Length:*) cgilite_response="$cgilite_response${BR}$l"; cgilite_cl='x';;
-      $CR) if [ "$cgilite_cl" ]; then
-             printf '%s %s\r\n%s\n\r\n' \
-               'HTTP/1.1' "${cgilite_status%${CR}}" \
-               "$cgilite_response"
-             cat; exit 0
-           else
-             printf '%s %s\r\n%s\n%s\r\n\r\n' \
-               'HTTP/1.1' "${cgilite_status%${CR}}" \
-               "$cgilite_response" "Connection: close"
-             cat; exit 1
-           fi;;
+      Content-Length:*) cgilite_cl="${l}";;
+      $CR) printf '%s %s\r\n%s\n%s\n\r\n' \
+             'HTTP/1.1' "${cgilite_status%${CR}}" \
+             "$cgilite_response" "${cgilite_cl}" |tee /dev/stderr
+           cat;
+           [ "${cgilite_cl#Connection}" = "${cgilite_cl}" ] && exit 0 || exit 1;;
       *) cgilite_response="$cgilite_response${BR}$l";;
     esac; done || exit 0;
     (sleep $cgilite_timeout && kill $$) & cgilite_watchdog=$!
       *) cgilite_response="$cgilite_response${BR}$l";;
     esac; done || exit 0;
     (sleep $cgilite_timeout && kill $$) & cgilite_watchdog=$!