Pair<String, String> setCookie(String key, String value, Maybe<Time> expires=nothing, Maybe<String> path=nothing, Maybe<String> domain=nothing, Bool secure=false)
Arguments
key: The name of the cookievalue: The value of the cookieexpires: The time that the cookie expires, which must be in GMT, ornothingif the cookie is a "session cookie" that expires when the web browser is closed (the default).path: The URL path to which the cookie will be returned. The default isnothingwhich sets it to the URL path of the current document. The URL path must begin with a '/' if it is explicitly set.domain: The domain that the cookies will be sent to. The default ofnothinggives the current hostname.secure: If true (the default is false) this cookie will only be sent back to the server over HTTPS connections. Use this if the cookie contains or can be used to access any sensitive information unless you do not have HTTPS available.
Usage
Creates a cookie header that can be passed to HTMLDocument::addHTTPHeader or added to the headers list for functions such as Webapp::displayPage. Remember that cookies are not available in the page that sets them, since the web browser has not yet received them to send back at that point.
expires = gmTime(time()+3600); // one hour later
cookie = setCookie("session",newSession(),just(expires));
addHTTPHeader(doc,cookie);
The original Netscape cookie specification has more detail on the use of these fields.
The functioning of the domain part is sometimes problematic. For example, there is no way to set a cookie that should be returned to server.example.com but not to test.server.example.com.