class RequestBody < Body
- Inherits from
Body: #stream?, #read, #call, #close_input, #close_output, #inspect, #empty?, #ready?, #rewindable?, #rewind, #buffered, #length, #each, #join, #finish, #discard, #as_json, #to_json, #to_io
A request body is used on the client side to generate the request body using a block.
As the response body isn't available until the request is sent, the response body must be Protocol::HTTP::Body::Streamable::RequestBody#streamed into the request body.
Definitions
def initialize(block)
Initialize the request body with the given block.
Signature
-
parameter
blockProc The block that generates the body.
Implementation
def initialize(block)
super(block, Writable.new)
end
def close(error = nil)
Close will be invoked when all the input is read.
Implementation
def close(error = nil)
self.close_input(error)
end
def stream(body)
Stream the response body into the block's input.
Implementation
def stream(body)
body&.each do |chunk|
@input.write(chunk)
end
rescue => error
ensure
@input.close_write(error)
end