varrequest=require('request');varzlib=require('zlib');varoptions={url:'http://some.endpoint.com/api/',headers:{'X-some-headers':'Some headers','Accept-Encoding':'gzip, deflate',},encoding:null};request.get(options,function(error,response,body){if(!error&&response.statusCode==200){// If response is gzip, unzip firstvarencoding=response.headers['content-encoding']if(encoding&&encoding.indexOf('gzip')>=0){zlib.gunzip(body,function(err,dezipped){varjson_string=dezipped.toString('utf-8');varjson=JSON.parse(json_string);// Process the json..});}else{// Response is not gzipped}}});
The above will also fix for Incorrect header checkerror, with encoding: null option.