0

I'm trying to handle the response using transfer-encoding: gzip, chunked.

If you run the code below (e.g node server.js), you should get "foobar" in your console but the process seems to be hanging.

var HTTP    = require('http');
var request = require('request');
var ZLib    = require('zlib');

var server = HTTP.createServer();
server.on('request', function(req, res) {
  res.setHeader('transfer-encoding', 'gzip, chunked');
  ZLib.gzip('foo', function(error, buffer) {
    res.write(buffer);
    ZLib.gzip('bar', function(error, buffer2) {
      res.write(buffer2);
      res.end();
    });
  });
});
server.listen(3001);

request({
  gzip: true,
  url: 'http://localhost:3001'
}, function(error, response, body) {
  if (error) console.error(error);
  console.log(body);
});

I checked the code with curl localhost:3001 and it's responding with "foobar" as expected. So can Node handle transfer-encoding: gzip, chunked? Or am I doing something wrong?

  • `gzip` is generally a `Content-Encoding` value, not a `Transfer-Encoding` value. Are you sure you are approaching this right? – loganfsmyth Oct 17 '14 at 23:17
  • I'm not sure about the code I posted here. But `gzip` is a valid value for `transfer-encoding`. And `curl` is handling it correcly. – Troger Xentos Oct 18 '14 at 04:49
  • `transfer-encoding: gzip` applies to the transfer of data (not the content you send to client) so you don't have to tell `curl` to decompress it like you do with `content-enoding: gzip`. – Troger Xentos Oct 18 '14 at 05:02

0 Answers0