node.js - Handle response using transfer-encoding: gzip,chunked -
i'm trying handle response using transfer-encoding: gzip, chunked
.
if run code below (e.g node server.js
), should "foobar" in console process seems 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 code curl localhost:3001
, it's responding "foobar" expected. can node handle transfer-encoding: gzip, chunked
? or doing wrong?
node.js gzip chunked
No comments:
Post a Comment