繁体   English   中英

node.js经典示例奇怪的行为

[英]node.js classic example strange behavior

有一个经典的节点示例:

var http = require('http');
var s = http.createServer(function(req, res){
    res.writeHead(200, {'content-type':'text/plain'});
    res.write('hi there\n');
    setTimeout(function(){
        res.end('and here');
    },2000);
});
s.listen(8000);

当我跑步时

curl http://127.0.0.1:8000

一切正常,“嗨,在那里”,并超过2秒-“和这里”。 好。

但是当我更改字符串#4并删除\\ n时:

 res.write('hi there');

我看到延迟(2秒),并且同时在“ hi there”和“ and here”之间没有任何超时地输出

节点-v = 4.2.6

这是好事,这是坏事还是不重要?

似乎是浏览器特定的行为。 在chrome似乎缓冲并等待响应结束之前,firefox会立即显示数据。

答案似乎在注释中: it's a line-wise buffer, a buffer that flushes when it sees a line terminator.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM