Edit Page

req.headers

An object containing the predefined/custom header given in the current request.

Usage

#
req.headers;

Details

#

Often we want to check the headers of the current request. This can be done easily in Sails.

Example

#

Sample output of the req.headers object:

console.log(req.headers);

{ host: 'localhost:1337',
  connection: 'keep-alive',
  'cache-control': 'no-cache',
  'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36',
  accept: '*/*',
  'accept-encoding': 'gzip, deflate, sdch',
  'accept-language': 'en-US,en;q=0.8,hi;q=0.6',
  cookie: 'sdfkslddklfk; sails.sid=s%3skdlfjkj1231lsdfnsc,m' }

Note

#

If you want to access any specific, custom, or predefined header, it can be done with bracket notation:

req.headers['custom-header'];

or dot notation:

req.headers.host;

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

Reference