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??

1
  • Same is happening with me, I'm not able to find the reason. Cache control headers don't work with transfer-encoding header. Commented Sep 13, 2019 at 4:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.