diff --git a/lib/oauth2.js b/lib/oauth2.js index c7c8982..25510c2 100644 --- a/lib/oauth2.js +++ b/lib/oauth2.js @@ -3,7 +3,8 @@ var querystring= require('querystring'), https= require('https'), http= require('http'), URL= require('url'), - OAuthUtils= require('./_utils'); + OAuthUtils= require('./_utils'), + zlib = require("zlib"); exports.OAuth2= function(clientId, clientSecret, baseSite, authorizePath, accessTokenPath, customHeaders) { this._clientId= clientId; @@ -145,9 +146,18 @@ exports.OAuth2.prototype._executeRequest= function( http_library, options, post_ var request = http_library.request(options); request.on('response', function (response) { - response.on("data", function (chunk) { - result+= chunk - }); + + if (response.headers["content-encoding"] === "gzip") { + response.on("data", function (chunk) { + result += zlib.gunzipSync(chunk); + }); + } else { + response.on("data", function (chunk) { + result+= chunk; + }); + } + + response.on("close", function (err) { if( allowEarlyClose ) { passBackControl( response, result );