I am using http node.js module to make http requests. I want to force the webserver to return uncompressed data. [No gzip, No deflate].
Request headers
headers: {
'Accept-Encoding': 'gzip,deflate,sdch',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/31.0.1650.57 Chrome/31.0.1650.57 Safari/537.36',
}
I tried using this 'Accept-Encoding': '*;q=1,gzip=0'
but no luck.
I see two approaches:
I want to go for #1.
If you are making http requests to an external server you can't control, and it doesn't react to the Accept-Encoding
request header, then you must handle the compressed response and decompress it later. I suggest you using the zlib module. Here's an example:
var zlib = require('zlib');
//...
request.on('response', function(response){
var contentEncoding = response.headers['content-encoding'];
response.on('data', function(data){
switch(contentEncoding){
case 'gzip':
zlib.gunzip(data, function(error, body){
if(error){
//Handle error
} else {
//Handle decompressed response body
}
});
break;
case 'deflate':
zlib.inflate(data, function(error, body){
if(error){
//Handle error
} else {
//Handle decompressed response body
}
});
break;
default:
//Handle response body
break;
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With