]> git.plutz.net Git - shcgi/commitdiff
basic inetd support
authorpaul <paul@plutz.net>
Sat, 26 May 2018 15:23:34 +0000 (15:23 +0000)
committerpaul <paul@plutz.net>
Sat, 26 May 2018 15:23:34 +0000 (15:23 +0000)
svn path=/trunk/; revision=67

cgilite.sh

index e009a2fed49748e4a9fd9905861643818f766c0c..b6ccd7fc4feb25aa2771dc8b9d6547841e150c6d 100755 (executable)
 # set -o posix # ksh, not portable
 setopt -o OCTAL_ZEROES 2>&-
 
+BR="$(printf '\n')"
+CR="$(printf '\r')"
+
+if [ "$1" = '--inetd' -a -z "$REQUEST_METHOD" ]; then
+  REMOTE_ADDR="$TCPREMOTEIP"
+  SERVER_NAME="$TCPLOCALIP"
+  SERVER_PORT="$TCPLOCALPORT"
+
+  read REQUEST_METHOD REQUEST_URI SERVER_PROTOCOL
+  PATH_INFO="${REQUEST_URI%\?*}"
+  QUERY_STRING="${REQUEST_URI#*\?}"
+  HTTP_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%%: *}"
+
+  export REMOTE_ADDR SERVER_NAME SERVER_PORT REQUEST_METHOD REQUEST_URI SERVER_PROTOCOL \
+         PATH_INFO QUERY_STRING HTTP_CONTENT_LENGTH HTTP_COOKIE
+
+  . "$0" |sed '1{s;^Status: ;HTTP/1.0 ;; t; iHTTP/1.0 200 OK\r
+             }'
+  exit $?
+fi
+
 if [ "$REQUEST_METHOD" = POST -a "${HTTP_CONTENT_LENGTH:=${CONTENT_LENGTH:=0}}" -gt 0 ]; then
   cgilite_post="$(head -c "$HTTP_CONTENT_LENGTH")"
 fi
@@ -129,3 +155,4 @@ REDIRECT(){
   printf 'Status: 303 See Other\r\nLocation: %s\r\n\r\n' "$*"
   exit 0
 }
+