Force the web server to return uncompressed data (without gzip)

I am using the http node.js module for http requests , I want to force the web server 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 one 'Accept-Encoding': '*;q=1,gzip=0', but no luck.

I see two approaches:

  • Force the web server to return uncompressed data.
  • Unzip the compressed data using some nodeJs module

I want to go to # 1.

+4
source share
1 answer

HTTP- , , Accept-Encoding, . zlib. :

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;
     }
  });
});
+2

All Articles