如何从http.get响应(Node.js)确定块的数量

时间:2015-09-24 17:51:02

标签: javascript node.js http encoding chunks

我想知道是否有办法收集使用http.get请求页面时要发回的块数。我最初的想法是,在实际接收块之前,或许可以通过回调响应来确定它。

以例如:

http.get({
  hostname: 'io-chat.com',
  port: 80,
  path: '/js',
  headers: {'user-agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36'},
}, function (res) {
  var chunks = [];
  res.on("data",function(i){chunks.push(i)});
  res.on("end",function(){console.log(chunks.length)});
})

on“end”我有控制台打印接收了多少块我希望在收到它们之前获得这些信息,以便加载器可以知道预期有多少块。

此外,我想知道为什么我收到的似乎是范围内随机数的块。有时候在加载这个页面和其他页面时,我会得到一些从173到176的块。这是什么原因,这真的很重要吗?

0 个答案:

没有答案
相关问题