module Streamable
A body that invokes a block that can read and write to a stream.
In some cases, it's advantageous to directly read and write to the underlying stream if possible. For example, HTTP/1 upgrade requests, WebSockets, and similar. To handle that case, response bodies can implement stream?
and return true
. When stream?
returns true, the body should be consumed by calling call(stream)
. Server implementations may choose to always invoke call(stream)
if it's efficient to do so. Bodies that don't support it will fall back to using #each
.
When invoking call(stream)
, the stream can be read from and written to, and closed. However, the stream is only guaranteed to be open for the duration of the call(stream)
call. Once the method returns, the stream should be closed by the server.