class PhusionPassenger::Utils::TeeInput

“rack.input” of the Rack environment.
When processing uploads, Unicorn exposes a TeeInput object under
will not support any deviations from it.
strict interpretation of Rack::Lint::InputWrapper functionality and
specification on the public API. This class is intended to be a
like). This should fully conform to the Rack::Lint::InputWrapper
Rack application can use input notification (upload progress and
store. On the first pass, the input is only read on demand so your
while providing rewindable semantics through a File/StringIO backing
acts like tee(1) on an input input to provide a input-like stream

def self.client_body_buffer_size

amounts larger than this are buffered to the filesystem
returns the maximum size of request bodies to buffer in memory,
def self.client_body_buffer_size
  @@client_body_buffer_size
end

def self.client_body_buffer_size=(bytes)

amounts larger than this are buffered to the filesystem
sets the maximum size of request bodies to buffer in memory,
def self.client_body_buffer_size=(bytes)
  @@client_body_buffer_size = bytes
end

def close

def close
  @tmp.close
end

def consume!

consumes the stream of the socket
def consume!
  junk = ""
  nil while read(16 * 1024, junk)
end

def each

def each
  while line = gets
    yield line
  end
  self # Rack does not specify what the return value is here
end

def gets

def gets
  if socket_drained?
    @tmp.gets
  else
    tee(@socket.gets)
  end
end

def initialize(socket, env)

this unless you are writing an HTTP server.
Initializes a new TeeInput object. You normally do not have to call
def initialize(socket, env)
  @len = env[CONTENT_LENGTH]
  @len = @len.to_i if @len
  @socket = socket
  @tmp = @len && @len <= @@client_body_buffer_size ?
         StringIO.new("") : TmpIO.new("PassengerTeeInput")
end

def read(*args)

def read(*args)
  if socket_drained?
    @tmp.read(*args)
  else
    tee(@socket.read(*args))
  end
end

def rewind

def rewind
  return 0 if 0 == @tmp.size
  consume! if !socket_drained?
  @tmp.rewind # Rack does not specify what the return value is here
end

def size

def size
  @len and return @len
  pos = @tmp.pos
  consume!
  @tmp.pos = pos
  @len = @tmp.size
end

def socket_drained?

def socket_drained?
  if @socket
    if @socket.eof?
      @socket = nil
      true
    else
      false
    end
  else
    true
  end
end

def tee(buffer)

def tee(buffer)
  if buffer && buffer.size > 0
    @tmp.write(buffer)
  end
  buffer
end