From: paul Date: Fri, 31 Jul 2015 15:09:26 +0000 (+0000) Subject: introduced set_cookie function X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=c5358ed1fda98b17ed9ebda01de44847659fb7ec;p=cgilite introduced set_cookie function svn path=/trunk/; revision=11 --- 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' +}