I'm playing around with chunked transfer encoding using a readable stream in Node. My script sends a bunch of 'a's to the client via HTTP in a chunked manner over 10 seconds.
var Stream = require('stream');
var Http = require('http');
var incr = 0;
var myStream = new Stream.Readable;
myStream._read = function() {
var self = this;
setTimeout(function(){
incr === 100 ? self.push(null) : self.push('a');
incr++;
}, 100);
};
var server = Http.createServer(function(req, res){
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
myStream.pipe(res);
});
server.listen(3000);
When I use content-type
of text/html
, Chrome successively prints 'a's to the screen until it's finished. It's really quite beautiful.
However if I try text/plain
, Chrome will buffer up all the response before printing it.
So my question is why do only some content types have this behaviour and is there a definitive list of supported types anywhere?