4

when I attempt compress a response with zlib nodejs express changes the headers.

Code:

    var acceptEncoding = req.headers['accept-encoding'];
    if (!acceptEncoding) { acceptEncoding = ''; }
    if (acceptEncoding.match(/\bdeflate\b/)) {
        zlib.gzip(JSON.stringify(Response), function (err, result) {
            if (!err) {
                //res.writeHead(200, { 'content-encoding': 'gzip' });
                res.header('Content-Length', result.byteLength);
                res.setHeader('transfer-encoding', '');
                res.setHeader('content-encoding', 'deflate');
                res.send(result, 200);
            }
        });
    }
    if (acceptEncoding.match(/\bgzip\b/)) {
        zlib.gzip(JSON.stringify(Response), function (err, result) {
            if (!err) {
                //res.writeHead(200, { 'content-encoding': 'gzip' });
                res.header('Content-Length', result.byteLength);
                res.setHeader('transfer-encoding', '');
                res.setHeader('content-encoding', 'gzip');
                res.send(result, 200);
            }
        });
    }
    else {
        res.send(JSON.stringify(Response), 200);

Chrome response:

Screenshot:

Do anybody knows why doing that??

I am a Student
  • 1,570
  • 4
  • 21
  • 36
  • Same is happening with me, I'm not able to find the reason. Cache control headers don't work with transfer-encoding header. – Param Singh Sep 13 '19 at 04:37

0 Answers0