class Protocol::Rack::Input
This implementation is not always rewindable, to avoid buffering the input when handling large uploads. See {Rewindable} for more details.
The input stream is an ‘IO`-like object which contains the raw HTTP POST data. When applicable, its external encoding must be `ASCII-8BIT` and it must be opened in binary mode, for Ruby 1.9 compatibility. The input stream must respond to `gets`, `each`, `read` and `rewind`.
Wraps a streaming input body into the interface required by `rack.input`.
def close(error = nil)
def close(error = nil) @closed = true if @body @body.close(error) @body = nil end return nil end
def closed?
def closed? @closed or @body.nil? end
def each(&block)
@yields {|chunk| ...}
Enumerate chunks of the request body.
def each(&block) return to_enum unless block_given? return if closed? while chunk = read_partial yield chunk end end
def empty?
def empty? @body.nil? end
def initialize(body)
Initialize the input wrapper.
def initialize(body) @body = body @closed = false # Will hold remaining data in `#read`. @buffer = nil end
def read_next
def read_next if @body # User's may forget to call #close... if chunk = @body.read # If the user reads exactly the content length, we close the stream automatically: # https://github.com/socketry/async-http/issues/183 if @body.empty? @body.close @closed = true end return chunk else unless @closed # So if we are at the end of the stream, we close it automatically: @body.close @closed = true end return nil end elsif @closed raise IOError, "Stream is not readable, input has been closed!" end end
def rewind
`rewind` must be called without arguments. It rewinds the input stream back to the beginning. It must not raise Errno::ESPIPE: that is, it may not be a pipe or a socket. Therefore, handler developers must buffer the input data into some rewindable object if the underlying input stream is not rewindable.
Rewind the input stream back to the start.
def rewind if @body and @body.respond_to?(:rewind) # If the body is not rewindable, this will fail. @body.rewind @buffer = nil @finished = false @closed = false return true end return false end