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
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)
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!
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)
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