Read headers and work with cookies
$.headers holds the request headers with lowercase names. $.cookie(name) reads a cookie of the request and $.cookie(name, value, expiration) writes one to the response. Response headers are set on $.response.headers.
exports.install = function() {
ROUTE('GET /headers/', headers);
ROUTE('GET /visit/', visit);
};
function headers($) {
$.response.headers['x-powered-by-forge'] = 'yes';
$.json({ agent: $.headers['x-agent'] || null });
}
function visit($) {
var count = ($.cookie('visits') || '0').parseInt() + 1;
$.cookie('visits', count + '', '1 day');
$.json({ visits: count });
}