Monday, November 08, 2010 at 12:07 AM.
system.verbs.builtins.webserver.util.setCookie
on setCookie (adrParams, cookieName, cookieValue, cookieDomain="", cookieExpires="", cookiePath="/", flSecure=false) {
<<10/8/99; 6:47:12 AM by DW
<<New routine, encapsulates as much special knowledge as we can about creating cookies.
<<We read this spec carefully while writing this: http://home.netscape.com/newsref/std/cookie_spec.html
<<10/13/99; 6:57:13 AM by DW
<<If cookieExpires is a date, we do the date-to-string conversion for you, per the Netscape spec.
<<http://frontier.userland.com/discuss/msgReader$1869
local (s = cookieName + "=" + string.urlEncode (cookieValue));
if cookieDomain != "" {
s = s + "; domain=" + cookieDomain};
if typeOf (cookieExpires) == dateType { //10/13/99; 6:57:13 AM by DW
cookieExpires = date.netStandardString (cookieExpires);
cookieExpires [8] = '-';
cookieExpires [12] = '-'};
if sizeof (cookieExpires) > 0 {
s = s + "; expires=" + cookieExpires};
if sizeof (cookiePath) > 0 {
s = s + "; path=" + cookiePath};
if flSecure {
s = s + "; secure"};
bundle { //set the cookie in adrParams
local (adrcookie = @adrParams^.responseHeaders.["Set-Cookie"]);
if defined (adrcookie^) {
adrcookie^ = adrcookie^ + "\r\n" + s}
else {
adrcookie^ = s}};
return (s)}
<<bundle //test code
<<local (params)
<<new (tabletype, @params)
<<new (tabletype, @params.responseHeaders)
<<clipboard.putvalue (webserver.util.setCookie (@params, "test cookie", "12345", cookieExpires: date ("4/1/2034")))
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.