出于效率原因,Node.js 通常会缓冲消息头,直到调用 outgoingMessage.end() 或写入第一块消息数据。 然后它尝试将标头和数据打包到单个 TCP 数据包中。

通常是需要的(节省了 TCP 往返),但不是在第一个数据没有被发送的时候,直到可能很晚。 outgoingMessage.flushHeaders() 绕过优化并启动请求。

Compulsorily flushes the message headers

For efficiency reason, Node.js normally buffers the message headers until outgoingMessage.end() is called or the first chunk of message data is written. It then tries to pack the headers and data into a single TCP packet.

It is usually desired (it saves a TCP round-trip), but not when the first data is not sent until possibly much later. outgoingMessage.flushHeaders() bypasses the optimization and kickstarts the request.