From feabb20748b12c9fee182471a7e54a257419d8a0 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Thu, 17 Sep 2015 02:04:30 +0200 Subject: [PATCH] Send depending on body type --- lib/cartodb/controllers/base.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/cartodb/controllers/base.js b/lib/cartodb/controllers/base.js index f9df51d9..c656436c 100644 --- a/lib/cartodb/controllers/base.js +++ b/lib/cartodb/controllers/base.js @@ -163,9 +163,19 @@ BaseController.prototype.send = function(req, res, body, status, headers) { res.set(headers); } - res.send.apply(res, args); + res.status(status); - if (req.profiler ) { + if (!Buffer.isBuffer(body) && typeof body === 'object') { + if (req.query && req.query.callback) { + res.jsonp(body); + } else { + res.json(body); + } + } else { + res.send(body); + } + + if (req.profiler) { try { // May throw due to dns, see // See http://github.com/CartoDB/Windshaft/issues/166