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?