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.
Invoking call(stream) transfers ownership of the stream to the called body. The body may read from and write to the stream, and must close it before returning. The caller must consider the stream closed and unusable after call(stream) returns.
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 |