Skip to content

Instantly share code, notes, and snippets.

@RubenVerborgh
Created March 5, 2014 17:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RubenVerborgh/9372495 to your computer and use it in GitHub Desktop.
Save RubenVerborgh/9372495 to your computer and use it in GitHub Desktop.
Requesting a representation through HTTP with GZIP compression
var request = require('request'),
zlib = require('zlib');
var headers = { 'Accept-Encoding': 'gzip' };
var response = request({ url:'http://perdu.com/', headers: headers });
response.on('response', function (response) {
// decode the stream if necessary
if (response.headers['content-encoding'] === 'gzip')
response = response.pipe(zlib.createGunzip());
// handle the stream
response.pipe(process.stdout);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment