ForgeTotal.js 5
en

Total.js 5

Read headers and work with cookies

Total.js 5 · total5@0.0.19 routingheaderscookies Executed against Total.js 5

$.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.

controllers/headers.js
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 });
}