Module: Protocol::HTTP::Body::Streamable
- Defined in:
- lib/protocol/http/body/streamable.rb
Overview
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.
Defined Under Namespace
Classes: Body, ConsumedError, Output, RequestBody, ResponseBody
Class Method Summary collapse
-
.request(&block) ⇒ Object
Generate a new streaming request body using the given block to generate the body.
-
.response(request, &block) ⇒ Object
Generate a new streaming response body using the given block to generate the body.
Class Method Details
.request(&block) ⇒ Object
Generate a new streaming request body using the given block to generate the body.
24 25 26 |
# File 'lib/protocol/http/body/streamable.rb', line 24 def self.request(&block) RequestBody.new(block) end |
.response(request, &block) ⇒ Object
Generate a new streaming response body using the given block to generate the body.
33 34 35 |
# File 'lib/protocol/http/body/streamable.rb', line 33 def self.response(request, &block) ResponseBody.new(block, request.body) end |