]> git.plutz.net Git - clickslide/commitdiff
function for reading http headers
authorpaul <paul@plutz.net>
Thu, 21 Jun 2018 11:37:36 +0000 (11:37 +0000)
committerpaul <paul@plutz.net>
Thu, 21 Jun 2018 11:37:36 +0000 (11:37 +0000)
svn path=/trunk/; revision=70

cgilite.sh

index 394bb8f6a24fa4723c3892a0480b82649f802fee..b90899344f849fb5e71f262a630ee1482e1aeadf 100755 (executable)
@@ -26,19 +26,19 @@ BR="$(printf '\n')"
 CR="$(printf '\r')"
 
 if [ "$1" = '--inetd' -a -z "$REQUEST_METHOD" ]; then
-  REMOTE_ADDR="$TCPREMOTEIP"
-  SERVER_NAME="$TCPLOCALIP"
-  SERVER_PORT="$TCPLOCALPORT"
+  REMOTE_ADDR="${TCPREMOTEIP:-$NCAT_REMOTE_ADDR}"
+  SERVER_NAME="${TCPLOCALIP:-$NCAT_LOCAL_ADDR}"
+  SERVER_PORT="${TCPLOCALPORT:-$NCAT_LOCAL_PORT}"
 
   read REQUEST_METHOD REQUEST_URI SERVER_PROTOCOL
   PATH_INFO="${REQUEST_URI%\?*}"
   QUERY_STRING="${REQUEST_URI#*\?}"
-  HTTP_HEADERS="$(sed -u '/^\r\?$/q')"
+  cgilite_headers="$(sed -u '/^\r\?$/q')"
 
-  HTTP_CONTENT_LENGTH="$(printf %s "$HTTP_HEADERS" |grep -oiE '^Content-Length: [0-9]+')"
-  HTTP_CONTENT_LENGTH="${HTTP_CONTENT_LENGTH##*: }"
-  HTTP_COOKIE="$(printf %s "$HTTP_HEADERS" |grep -oiE '^Cookie: [^\r]+')"
-  HTTP_COOKIE="${HTTP_COOKIE##*: }"
+  HTTP_CONTENT_LENGTH="$(printf %s "$cgilite_headers" |grep -oiE '^Content-Length: [0-9]+')"
+  HTTP_CONTENT_LENGTH="${HTTP_CONTENT_LENGTH#*: }"
+  HTTP_COOKIE="$(printf %s "$cgilite_headers" |grep -oiE '^Cookie: [^\r]+')"
+  HTTP_COOKIE="${HTTP_COOKIE#*: }"
 
   export REMOTE_ADDR SERVER_NAME SERVER_PORT REQUEST_METHOD REQUEST_URI SERVER_PROTOCOL \
          PATH_INFO QUERY_STRING HTTP_CONTENT_LENGTH HTTP_COOKIE
@@ -90,6 +90,11 @@ POST_COUNT(){ cgilite_count POST $1; }
 REF(){ cgilite_value REF $@; }
 REF_COUNT(){ cgilite_count REF $1; }
 
+HEADER(){
+  printf %s "$cgilite_headers" \
+  | sed -rn '/^'"${1}"': /{s;^[^:]+: ([^\r]+)\r?$;\1;p;q;}'
+}
+
 COOKIE(){
   printf "$(
     printf %s " ${HTTP_COOKIE}" \