Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1491

node https & zlib package: can't parse gzip'ed response from stackoverflow.com

$
0
0

gunzip ing the response doesn't work (I definitely get a gzip response), the headers aren't right, I really don't get why. Here's the demo code below:

const https = require('https')const zlib = require('zlib')const options = {  headers: {'Accept-Encoding': 'gzip'  },}https.get('https://stackoverflow.com/', options, resp => {  let data = "";  resp.on("data", chunk => {    data += chunk;  });  resp.on("end", () => {    if (resp.headers['content-encoding'] != 'gzip') {      console.log('should get gzip')      process.exit(1)    }    console.log('got gzip!')    zlib.gunzip(data, data_ungzip => {      console.log(data_ungzip)    })  });})

output:

got gzip!Error: incorrect header check    at Zlib.zlibOnError [as onerror] (zlib.js:187:17) {  errno: -3,  code: 'Z_DATA_ERROR'}

Viewing all articles
Browse latest Browse all 1491

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>