Skip to content

Commit

Permalink
support JSON APIs that don't set the write content type
Browse files Browse the repository at this point in the history
  • Loading branch information
benatkin committed Aug 2, 2011
1 parent 1cb1ec1 commit 4f8d2df
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@ Request.prototype.request = function () {
})
options.on("end", function () {
response.body = buffer
if (options.json && response.headers['content-type'] === 'application/json' && response.body != '') {
response.body = JSON.parse(response.body)
if (options.json) {
try {
response.body = JSON.parse(response.body)
} catch (e) {}
}
options.callback(null, response, response.body)
})
Expand Down

0 comments on commit 4f8d2df

Please sign in to comment.