Javascript http模块上的node.js response.writeHead
我正在实现自己的http模块。 在阅读官方node.js http模块api时,我无法理解以下几点:Javascript http模块上的node.js response.writeHead,javascript,node.js,http,Javascript,Node.js,Http,我正在实现自己的http模块。 在阅读官方node.js http模块api时,我无法理解以下几点: 如果用户正在使用response.writeHead(statusCode、[reasonPhrase]、[headers])函数,那么这些头应该立即写入套接字,还是应该首先作为对象的成员保存?然后只在.end()函数之后写入 当用户不使用writeHead()时,应该使用的隐式头的含义是什么?他们应该提前吗?如果用户没有设置它们呢?行为应该是什么?谢谢 我找到了第一个问题的答案,但仍然不理解第
response.writeHead(statusCode、[reasonPhrase]、[headers])
函数,那么这些头应该立即写入套接字,还是应该首先作为对象的成员保存?然后只在.end()
函数之后写入writeHead()
时,应该使用的隐式头的含义是什么?他们应该提前吗?如果用户没有设置它们呢?行为应该是什么?谢谢我找到了第一个问题的答案,但仍然不理解第二个问题
The first time response.write() is called, it will send the buffered header information and the first body to the client. The second time response.write() is called, Node assumes you're going to be streaming data, and sends that separately. That is, the response is buffered up to the first chunk of body.
答复:
writeHead
的标头还是带有write
的正文,都会被缓冲并发送。您可以看到,它们使用套接字缓冲区。在发送之前,它们只能保存固定数量的数据。需要记住的重要事实是,在开始编写正文之前,只能设置标题。如果这样做,http服务器本身将为您设置一些头所以实际上我找到了第一个问题的答案,所以我只留下了第二个问题