Skip to content

Instantly share code, notes, and snippets.

@pathsny
Created January 2, 2012 05:41
Show Gist options
  • Save pathsny/1549496 to your computer and use it in GitHub Desktop.
Save pathsny/1549496 to your computer and use it in GitHub Desktop.
gzip http data
var http = require('http');
zlib = require('zlib')
var request = http.get({ host: 'www.desilva.biz',
path: '/php/zlib.html',
port: 80,
headers: { 'accept-encoding': 'gzip,deflate' } });
request.on('response', function(resp){
var headers = resp.headers['content-encoding']
console.log(headers)
console.log('response')
console.log(headers.search('gzip') === -1 && headers.search('deflate') === -1)
var sol = '';
res2 = resp.pipe(zlib.createGunzip());
res2.on('data', function(chunk){
console.log(chunk)
sol += chunk;
});
res2.on('end', function(chunk){
console.log(chunk)
sol += chunk;
console.log("sol", sol);
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment