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.

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.

Nested Classes and Modules

class Output

A output stream that can be written to by a block.

class ConsumedError

Raised when a streaming body is consumed more than once.

class Body

A streaming body that can be read from and written to.

class ResponseBody

A response body is used on the server side to generate the response body using a block.

class RequestBody

A request body is used on the client side to generate the request body using a block.

Definitions

def self.request(&block)

Generate a new streaming request body using the given block to generate the body.

Signature

parameter block Proc

The block that generates the body.

returns RequestBody

The streaming request body.

Implementation

def self.request(&block)
	RequestBody.new(block)
end

def self.response(request, &block)

Generate a new streaming response body using the given block to generate the body.

Signature

parameter request Request

The request.

parameter block Proc

The block that generates the body.

returns ResponseBody

The streaming response body.

Implementation

def self.response(request, &block)
	ResponseBody.new(block, request.body)
end