def initialize(params, initial_body, socket)
@params = params
@socket = socket
clen = params[Const::CONTENT_LENGTH].to_i - initial_body.length
if clen > Const::MAX_BODY
@body = Tempfile.new(Const::MONGREL_TMP_BASE)
@body.binmode
else
@body = StringIO.new
end
begin
@body.write(initial_body)
clen -= @body.write(@socket.read(clen % Const::CHUNK_SIZE))
while clen > 0
data = @socket.read(Const::CHUNK_SIZE)
raise "Socket closed or read failure" if not data or data.length != Const::CHUNK_SIZE
clen -= @body.write(data)
end
@body.rewind
rescue Object
STDERR.puts "Error reading request: #$!"
@body.delete if @body.class == Tempfile
@body = nil
end
end