Skip to content

Instantly share code, notes, and snippets.

@dpogorzelski
Created May 21, 2013 15:53
Show Gist options
  • Save dpogorzelski/5620910 to your computer and use it in GitHub Desktop.
Save dpogorzelski/5620910 to your computer and use it in GitHub Desktop.
Read http request's body which has a gzip content encoding (node.js);
var https = require('https');
var gunzip = require('zlib').createGunzip();
var options = {
host: 'api.stackexchange.com',
path: '/2.1/info?site=stackoverflow'
};
https.get(options, function(res) {
var body = '';
res.pipe(gunzip);
gunzip.on('data', function (data) {
body += data;
});
gunzip.on('end', function() {
console.log(JSON.parse(body));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment