Permalink
Browse files

Automatically decode JSON responses based on Content-type

  • Loading branch information...
1 parent e82dd8a commit 0bd71bb293d5a9944bed3350e24007029e902082 @nylen committed Oct 9, 2012
Showing with 6 additions and 1 deletion.
  1. +6 −1 main.js
View
@@ -650,8 +650,13 @@ Request.prototype.start = function () {
try {
response.body = JSON.parse(response.body)
} catch (e) {}
+ } else if (response.headers && response.headers['content-type']) {
+ var contentType = response.headers['content-type'].split(';')[0]
+ if (contentType == 'application/json') {
+ response.body = JSON.parse(response.body)
+ }
}
-
+
self.emit('complete', response, response.body)
})
}

0 comments on commit 0bd71bb

Please sign in to comment.