From e52cd28f1ee1e74af0aeb9532b938c4b14e5f9f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Fri, 16 Mar 2018 17:13:48 +0100 Subject: [PATCH] User res.body as placeholder of the response's body --- lib/cartodb/controllers/named_maps.js | 36 ++++++++++++++++----------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/cartodb/controllers/named_maps.js b/lib/cartodb/controllers/named_maps.js index b6fcd350..6bff861c 100644 --- a/lib/cartodb/controllers/named_maps.js +++ b/lib/cartodb/controllers/named_maps.js @@ -224,9 +224,11 @@ function getTile ({ tileBackend, label }) { return next(err); } - res.locals.body = tile; - res.locals.headers = headers; - res.locals.stats = stats; + if (headers) { + res.set(headers); + } + + res.body = tile; next(); }); @@ -350,28 +352,36 @@ function getImage({ previewBackend, label }) { if (zoom !== undefined && center) { return previewBackend.getImage(namedMapProvider, format, width, height, zoom, center, (err, image, headers, stats) => { + req.profiler.add(stats); + if (err) { err.label = label; return next(err); } - res.locals.body = image; - res.locals.headers = headers; - res.locals.stats = stats; + if (headers) { + res.set(headers); + } + + res.body = image; next(); }); } previewBackend.getImage(namedMapProvider, format, width, height, bounds, (err, image, headers, stats) => { + req.profiler.add(stats); + if (err) { err.label = label; return next(err); } - res.locals.body = image; - res.locals.headers = headers; - res.locals.stats = stats; + if (headers) { + res.set(headers); + } + + res.body = image; next(); }); @@ -498,9 +508,8 @@ function setCacheControlHeader () { function setContentTypeHeader () { return function setContentTypeHeaderMiddleware(req, res, next) { - const { headers = {} } = res.locals; - res.set('Content-Type', headers['content-type'] || headers['Content-Type'] || 'image/png'); + res.set('Content-Type', res.get('content-type') || res.get('Content-Type') || 'image/png'); next(); }; @@ -508,12 +517,11 @@ function setContentTypeHeader () { function sendResponse () { return function sendResponseMiddleware (req, res) { - const { body, stats = {}, format } = res.locals; + const { format } = res.locals; req.profiler.done('render-' + format); - req.profiler.add(stats); res.status(200); - res.send(body); + res.send(res.body); }; }