diff --git a/main.js b/main.js index b12fccf8f..683466f86 100644 --- a/main.js +++ b/main.js @@ -289,7 +289,10 @@ Request.prototype.request = function () { }) options.on("end", function () { response.body = buffer - options.callback(null, response, buffer) + if (options.json && response.headers['content-type'] === 'application/json') { + response.body = JSON.parse(response.body) + } + options.callback(null, response, response.body) }) } } diff --git a/tests/test-body.js b/tests/test-body.js index 4d4cfbc7c..7686965e8 100644 --- a/tests/test-body.js +++ b/tests/test-body.js @@ -65,8 +65,7 @@ for (i in tests) { request(test, function (err, resp, body) { if (err) throw err; if (test.expectBody) { - if (test.expectBody !== body) console.log(test.expectBody, body); - assert.equal(test.expectBody, body) + assert.deepEqual(test.expectBody, body) } counter = counter - 1; if (counter === 0) {