Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Automatically decode JSON responses based on Content-type

  • Loading branch information...
commit 0bd71bb293d5a9944bed3350e24007029e902082 1 parent e82dd8a
James Nylen authored October 09, 2012

Showing 1 changed file with 6 additions and 1 deletion. Show diff stats Hide diff stats

  1. 7  main.js
7  main.js
@@ -650,8 +650,13 @@ Request.prototype.start = function () {
650 650
             try {
651 651
               response.body = JSON.parse(response.body)
652 652
             } catch (e) {}
  653
+          } else if (response.headers && response.headers['content-type']) {
  654
+            var contentType = response.headers['content-type'].split(';')[0]
  655
+            if (contentType == 'application/json') {
  656
+              response.body = JSON.parse(response.body)
  657
+            }
653 658
           }
654  
-          
  659
+
655 660
           self.emit('complete', response, response.body)
656 661
         })
657 662
       }

0 notes on commit 0bd71bb

Please sign in to comment.
Something went wrong with that request. Please try again.