class HTTP::Response::Body

def to_s

Returns:
  • (String) - eagerly consume the entire body as a string
def to_s
  return @contents if @contents
  raise StateError, "body is being streamed" unless @streaming.nil?
  begin
    @streaming  = false
    @contents   = String.new("").force_encoding(@encoding)
    while (chunk = @stream.readpartial)
      @contents << chunk.force_encoding(@encoding)
      chunk.clear # deallocate string
    end
  rescue
    @contents = nil
    raise
  end
  @contents
end