簡體   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