Created
March 5, 2014 17:47
-
-
Save RubenVerborgh/9372495 to your computer and use it in GitHub Desktop.
Requesting a representation through HTTP with GZIP compression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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