X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=cgilite.sh;h=79982884dfffffb91e83c6f8392c72e5becdaa1a;hp=1f2ebb3c9e03177d26e84a096d5c71243b00aefb;hb=834d4f0a184151bde1ab29bafa1170277247f8f9;hpb=44d80696c763f4e8c8102ea8d8c570e686fbff4e diff --git a/cgilite.sh b/cgilite.sh index 1f2ebb3..7998288 100755 --- a/cgilite.sh +++ b/cgilite.sh @@ -81,11 +81,23 @@ if [ -z "$REQUEST_METHOD" -a -z "$SERVER_PROTOCOL" ]; then # Without Content-Length header, connection will terminate after # script. + cgilite_status='200 OK'; cgilite_response=''; cgilite_cl=''; . "$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 - Content-Length:*) printf '%s\n' "$l"; cat;; - $CR) printf 'Connection: close\r\n\r\n'; cat; exit 1;; - *) printf '%s\n' "$l";; + 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;; + *) cgilite_response="$cgilite_response${BR}$l";; esac; done || exit 0; (sleep $cgilite_timeout && kill $$) & cgilite_watchdog=$! done