From 8907082a85ef965d2c0de7e4d81592f656273a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 19 Jul 2017 12:24:37 +0200 Subject: [PATCH] Parse body relying on content-type header --- test/support/test-client.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/test/support/test-client.js b/test/support/test-client.js index 80bc9223..48ef0eb5 100644 --- a/test/support/test-client.js +++ b/test/support/test-client.js @@ -575,20 +575,18 @@ TestClient.prototype.getTile = function(z, x, y, params, callback) { assert.response(self.server, request, expectedResponse, function(res, err) { assert.ifError(err); - var obj; + var body; - if (isPng) { - obj = mapnik.Image.fromBytes(new Buffer(res.body, 'binary')); - } else if (isMvt) { - if (res.body) { - obj = new mapnik.VectorTile(z, x, y); - obj.setDataSync(new Buffer(res.body, 'binary')); - } - } else { - obj = JSON.parse(res.body); + if (res.headers['content-type'] === 'image/png') { + body = mapnik.Image.fromBytes(new Buffer(res.body, 'binary')); + } else if (res.headers['content-type'] === 'application/x-protobuf') { + body = new mapnik.VectorTile(z, x, y); + body.setDataSync(new Buffer(res.body, 'binary')); + } else if (res.headers['content-type'] === 'application/json; charset=utf-8') { + body = JSON.parse(res.body); } - next(null, res, obj); + next(null, res, body); }); }, function finish(err, res, image) {