Description
When writing via the regular res.write()
, under normal circumstances, data always reaches the browser.
This is also the case when the connection is never-ending, and data is pushed to write()
as it becomes available. For example when data comes in small portions interspersed with pauses.
The Nagle algorithm makes sure that data reaches the browser in this case. The default setting on Linux is to wait 40 milliseconds, and if no further writes have happened, flush the data to the network.
When the compression
module is included via app.use()
, this no longer happens. There is a buffer in the zlib
library which holds on to the data forever, and it never reaches the browser.
This feature request is to implement the following:
- When a
write()
happens, set or reset a 40 millisecond timer. - If the timer runs out, call zlib to
flush()
the data to the browser.
That way, we retain the semantics of the original res.write()
.
Implementation ideas below.
I imagine that one way to implement this would be a "nagle" writable stream running on top of the gzip stream.
When the "nagle" stream's pipe() method is called, it looks if the passed stream is "instanceof Gzip".
If so, set an internal property to reference the underlying stream, so that we can later call flush()
on it when a timer runs out.