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

这通常是需要的(节省了 TCP 往返),但是当第一个数据直到可能很晚才发送时才需要。 request.flushHeaders() 绕过优化并启动请求。

Flushes the request headers.

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

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