Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Automatically decode JSON responses based on Content-type #339

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+6 −1
Split
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)
})
}