class Rackup::Stream

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.

def <<(buffer)

def <<(buffer)
  write(buffer)
end

def close(error = nil)

Close the input and output bodies.
def close(error = nil)
  self.close_read
  self.close_write
  return nil
ensure
  @closed = true
end

def close_read

def close_read
  @input&.close
  @input = nil
end

def close_write

close must never be called on the input stream. huh?
def close_write
  if @output.respond_to?(:close)
    @output&.close
  end
  @output = nil
end

def closed?

Whether the stream has been closed.
def closed?
  @closed
end

def empty?

Whether there are any output chunks remaining?
def empty?
  @output.empty?
end

def flush

def flush
end

def initialize(input = nil, output = Buffered.new)

def initialize(input = nil, output = Buffered.new)
  @input = input
  @output = output
  raise ArgumentError, "Non-writable output!" unless output.respond_to?(:write)
  # Will hold remaining data in `#read`.
  @buffer = nil
  @closed = false
end

def read_next

def read_next
  if @input
    return @input.read
  else
    @input = nil
    raise IOError, "Stream is not readable, input has been closed!"
  end
end

def write(buffer)

def write(buffer)
  if @output
    @output.write(buffer)
    return buffer.bytesize
  else
    raise IOError, "Stream is not writable, output has been closed!"
  end
end

def write_nonblock(buffer)

def write_nonblock(buffer)
  write(buffer)
end