# Read headers and work with cookies

> Read request headers from $.headers, read and write cookies with $.cookie() and set response headers.

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: en
Content-SHA256: a51d21c0651683626fd6156136be4c9f8365400b440e26a59bf982bda65251c4
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

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

```js 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 });
}
```
