]> git.plutz.net Git - cgilite/commitdiff
introduced set_cookie function
authorpaul <paul@plutz.net>
Fri, 31 Jul 2015 15:09:26 +0000 (15:09 +0000)
committerpaul <paul@plutz.net>
Fri, 31 Jul 2015 15:09:26 +0000 (15:09 +0000)
svn path=/trunk/; revision=11

cgi.sh

diff --git a/cgi.sh b/cgi.sh
index d9ee5bd012ed8b3780a4ed78ae75c8f82dda0d0a..e994daa99d2ff50d68eeaab5703c2ec8a01d611d 100755 (executable)
--- a/cgi.sh
+++ b/cgi.sh
@@ -91,3 +91,17 @@ redirect(){
   printf '%s\n\n' "Location: $*"
   exit 0
 }
+
+set_cookie(){
+  case "$1" in
+    session|0) expire='';;
+    ''|default)        expire="$(LANG=C date -d "+ 1 week" +'%a, %d %b %Y %T %Z')";;
+    *)         expire="$(LANG=C date -d "$1" +'%a, %d %b %Y %T %Z' 2>&-)";;
+  esac
+  cookie="$2"
+  
+  printf 'Set-Cookie: %s' "$cookie"
+  [ -n "$expire" ] && printf '; Expires=%s' "$expire" 
+  [ $# -ge 3 ] && shift 2 && printf '; %s' "$@"
+  printf '\n'
+}