Don't send headers if they're not asked for

This commit is contained in:
Remy Sharp 2014-08-18 16:42:57 +01:00
parent ba362b6b74
commit ee4792c782
2 changed files with 2 additions and 2 deletions

View File

@ -51,7 +51,7 @@ var middleware = module.exports = {
var origin = req.header('Origin');
// TODO should this check if the request is via the API?
if (req.method === 'OPTIONS' || (req.method === 'GET' && utils.isAjax(req)) || (req.method === 'GET' && req.headers.origin)) {
if (req.method === 'OPTIONS' || (req.method === 'GET' && req.headers.origin)) {
res.header({
'Access-Control-Allow-Origin': origin,
'Access-Control-Allow-Headers': headers,

View File

@ -133,7 +133,7 @@ module.exports = {
return collected;
},
isAjax: function (req) {
return (req.get('X-Requested-With') || '').toLowerCase() === 'xmlhttprequest';
return (req.get('X-Requested-With') || '').toLowerCase() === 'xmlhttprequest' || req.accepted[0].value === 'application/json';
},
shortcode: function (length) {
var vowels = 'aeiou',