]> git.plutz.net Git - cgilite/blobdiff - cgi.sh
fill REQUEST_URI variable
[cgilite] / cgi.sh
diff --git a/cgi.sh b/cgi.sh
index 7b5651af6eec81d3f9720bfd9227b03ac626960e..30e6d769015d74ce4dc645e5225f148272d6836e 100755 (executable)
--- a/cgi.sh
+++ b/cgi.sh
@@ -34,17 +34,11 @@ printf '%s\n' "$QUERY_STRING" |tr '&' '\n' |while read query; do
   debug "_GET[$key] => $val"
 done
 
-if [ "$REQUEST_METHOD" = POST -a "$HTTP_CONTENT_LENGTH" -gt 0 ]; then
+if [ "$REQUEST_METHOD" = POST -a "${HTTP_CONTENT_LENGTH:=$CONTENT_LENGTH}" -gt 0 ]; then
   # parse HTTP POST string
   debug "== CGI DATA: POST =="
   head -c "$HTTP_CONTENT_LENGTH" \
-  | sed -un '
-    2q
-    1{
-      s;&;\n;g;
-      a
-      p
-    }' \
+  | sed -un 's;&;\n;g; p; q' \
   | while read query; do
     key="$(printf %s "$query" |sed -r 's:^([\.a-zA-Z0-9_-]+)=(.*)$:\1:')"
     val="$(printf %s "$query" |sed -r 's:^([\.a-zA-Z0-9_-]+)=(.*)$:\2:')"
@@ -117,7 +111,8 @@ attribsafe(){
   # except alphanumerig ascii
 
   printf %s "$*" \
-  | hexdump -v -e '/1 "&#x%02X;"' \
+  | iconv -f utf-8 -t utf32le \
+  | hexdump -v -e '/4 "&#x%02X;"' \
   | sed 's;&#x30\;;0;g; s;&#x31\;;1;g; s;&#x32\;;2;g; s;&#x33\;;3;g; s;&#x34\;;4;g; s;&#x35\;;5;g;
          s;&#x36\;;6;g; s;&#x37\;;7;g; s;&#x38\;;8;g; s;&#x39\;;9;g;
          s;&#x41\;;A;g; s;&#x42\;;B;g; s;&#x43\;;C;g; s;&#x44\;;D;g; s;&#x45\;;E;g; s;&#x46\;;F;g;
@@ -133,7 +128,7 @@ attribsafe(){
 }
 
 redirect(){
-  printf '%s\n\n' "Location: $*"
+  printf '%s\r\n\r\n' "Location: $*"
   exit 0
 }
 
@@ -148,5 +143,5 @@ set_cookie(){
   printf 'Set-Cookie: %s' "$cookie"
   [ -n "$expire" ] && printf '; Expires=%s' "$expire" 
   [ $# -ge 3 ] && shift 2 && printf '; %s' "$@"
-  printf '\n'
+  printf '\r\n'
 }