]> git.plutz.net Git - cgilite/commitdiff
speed improvements
authorPaul Hänsch <paul@plutz.net>
Wed, 27 May 2020 02:10:20 +0000 (04:10 +0200)
committerPaul Hänsch <paul@plutz.net>
Wed, 27 May 2020 02:10:20 +0000 (04:10 +0200)
cgilite.sh

index 4c6de8ca6b784a5a361fb5cd8d70208c1a4d701d..60dd9d7b4ba0444fd93bfbb5a79bbaea76e56d9e 100755 (executable)
@@ -31,8 +31,10 @@ HEADER(){
   # Read value of header line. Use this instead of
   # referencing HTTP_* environment variables.
   if [ -n "${cgilite_headers+x}" ]; then
-    printf %s "$cgilite_headers" \
-    | sed -En 's;^'"${1}"': ([^\r]+)\r?$;\1;i; tX; d; :X;p;q;'
+    local h="${BR}${cgilite_headers}"
+    [ "${h##*${BR}${1}: }" = "${h}" ] && return 1
+    h="${h##*${BR}${1}: }" h="${h%%${BR}*}"
+    printf %s "${h%${CR}}"
   else
     eval "printf %s \"\$HTTP_$(printf %s "${1}" |tr a-z A-Z |tr -c A-Z _)\""
   fi
@@ -71,9 +73,13 @@ if [ -z "$REQUEST_METHOD" ]; then
     kill $cgilite_watchdog
     PATH_INFO="$(HEX_DECODE "${REQUEST_URI%\?*}")"
     QUERY_STRING="${REQUEST_URI#*\?}"
-    cgilite_headers="$(while read -r hl; do [ "${hl%${CR}}" ] && printf '%s\n' "$hl" || break; done )"
+    cgilite_headers=''; while read -r hl; do
+      [ "${hl%${CR}}" ] || break
+      cgilite_headers="${cgilite_headers}${hl}${BR}"
+    done
 
-    HTTP_CONTENT_LENGTH="$(HEADER Content-Length |grep -xE '[0-9]+')"
+    HTTP_CONTENT_LENGTH="$(HEADER Content-Length)"
+    HTTP_CONTENT_LENGTH="${HTTP_CONTENT_LENGTH##*[^0-9]}"
 
     export REMOTE_ADDR SERVER_NAME SERVER_PORT REQUEST_METHOD REQUEST_URI SERVER_PROTOCOL \
            PATH_INFO QUERY_STRING HTTP_CONTENT_LENGTH
@@ -96,6 +102,8 @@ if [ -z "$REQUEST_METHOD" ]; then
     esac; done || exit 0;
     (sleep $cgilite_timeout && kill $$) & cgilite_watchdog=$!
   done
+  kill $cgilite_watchdog
+  exit 0
 fi
 
 if [ "$REQUEST_METHOD" = POST -a "${HTTP_CONTENT_LENGTH:=${CONTENT_LENGTH:=0}}" -gt 0 ]; then