From c5358ed1fda98b17ed9ebda01de44847659fb7ec Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 31 Jul 2015 15:09:26 +0000 Subject: [PATCH] introduced set_cookie function svn path=/trunk/; revision=11 --- cgi.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cgi.sh b/cgi.sh index d9ee5bd..e994daa 100755 --- 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' +} -- 2.39.2