From: paul Date: Thu, 21 Jun 2018 11:37:36 +0000 (+0000) Subject: function for reading http headers X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=c287482dc24988cabd48a085e6d752d12b489550;p=clickslide function for reading http headers svn path=/trunk/; revision=70 --- diff --git a/cgilite.sh b/cgilite.sh index 394bb8f..b908993 100755 --- a/cgilite.sh +++ b/cgilite.sh @@ -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}" \