lib/puma/server.rb
# Given the requset +env+ from +client+ and the partial body +body+
# plus a potential Content-Length value +cl+, finish reading
# the body and return it.
#
# If the body is larger than MAX_BODY, a Tempfile object is used
# for the body, otherwise a StringIO is used.
#


If the body is larger than MAX_BODY, a Tempfile object is used
for the body, otherwise a StringIO is used.
If the body is larger than MAX_BODY a Tempfile object is used for the body otherwise a StringIO is used .
def read_body(env, client, body, cl)
      content_length = cl.to_i
      remain = content_length - body.bytesize
      return StringIO.new(body) if remain <= 0
      if remain > MAX_BODY
        stream = Tempfile.new(Const::PUMA_TMP_BASE)
        stream.binmode
      else
        stream = StringIO.new
      end
      stream.write body
      chunk = client.readpartial(remain % CHUNK_SIZE)
      unless chunk
        stream.close
        return nil
      end
      remain -= stream.write(chunk)
      while remain > 0
        chunk = client.readpartial(CHUNK_SIZE)
        unless chunk
          stream.close
          return nil
        end
        remain -= stream.write(chunk)
      end
      stream.rewind
      return stream
    end
def read_body ( env , client , body , cl ) content_length = cl . to_i remain = content_length - body . bytesize return StringIO . new ( body ) if remain <= 0 if remain > MAX_BODY stream = Tempfile . new ( Const :: PUMA_TMP_BASE ) stream . binmode else stream = StringIO . new end stream . write body chunk = client . readpartial ( remain % CHUNK_SIZE ) unless chunk stream . close return nil end remain -= stream . write ( chunk ) while remain > 0 chunk = client . readpartial ( CHUNK_SIZE ) unless chunk stream . close return nil end remain -= stream . write ( chunk ) end stream . rewind return stream end
Given the requset +env+ from +client+ and the partial body +body+
plus a potential Content-Length value +cl+, finish reading
the body and return it.
Given the requset + env + from + client + and the partial body + body + plus a potential Content - Length value + cl + finish reading the body and return it .
# Use a Tempfile if there is a lot of data left # Read an odd sized chunk so we can read even sized ones # after this # No chunk means a closed socket # Raed the rest of the chunks
env
client
body
cl