[Tir] Cookie Handling Updated
- From:
- Matt Towers
- Date:
- 2011-09-01 @ 21:24
The cookie handling gear in Tir has been completely revamped and checked
in to master on GitHub. Most importantly, there are two breaking changes.
Web::get_cookie() has been removed.
Web::set_cookie(...) has been replaced with an incompatible method signature.
also,
Web::get_cookies() has been added.
Usage is as follows:
Web:get_cookies() - returns a table whose keys and values correspond to
the cookie values passed from the client in the HTTP request header. If
there are multiple cookies sent from the client with the same key, the
value associated with said key will be a table containing each of the
passed values for that key. For example:
{
my_key_1 = "my_value_1",
my_key_2 = "my_value_2",
my_key_3 = {
1 = "my_value_3_a",
2 = "my_value_3_b"
}
}
Web:set_cookie([table]) - creates a set-cookie HTTP header to be returned
to the calling client with a new key/value pair for the new cookie. The
passed table must be of the following form. This method may be called
multiple times with different cookies for a given response. If two
identical cookies are set, the cookie value passed from the client in the
next request will be indeterminate.
cookie = {
key="mykey", -- required
value="myvalue", -- required
domain='www.example.com', -- optional
expires=[UNIX epoch expiration date/time in seconds] --optional
http_only=[bool], --optional
seucre=[bool] --optional
}
For more information on what the various set-cookie parameters mean, check
out the wiki article on HTTP cookies:
http://en.wikipedia.org/wiki/HTTP_cookie
If anything doesn't work as expected or I missed anything, please let me know.
✈ Matt