Method: Rack::Lint::Wrapper#each

Defined in:
lib/rack/lint.rb

#eachObject

Enumerable Body

Raises:



852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
# File 'lib/rack/lint.rb', line 852

def each
  ## The Enumerable Body must respond to +each+,    raise LintError, "Enumerable Body must respond to each" unless @body.respond_to?(:each)

  ## which must only be called once,    raise LintError, "Response body must only be called once (#{@consumed})" unless @consumed.nil?

  ## must not be called after being closed,    raise LintError, "Response body is already closed" if @closed

  @consumed = :each

  @body.each do |chunk|
    ## and must only yield +String+ values.
    unless chunk.kind_of? String
      raise LintError, "Body yielded non-string value #{chunk.inspect}"
    end

    ##
    ## Middleware must not call +each+ directly on the Body. Instead, middleware can return a new Body that calls +each+ on the original Body, yielding at least once per iteration.
    if @lint[0] == self
      @env['rack.lint.body_iteration'] += 1
    else
      if (@env['rack.lint.body_iteration'] -= 1) > 0
        raise LintError, "New body must yield at least once per iteration of old body"
      end
    end

    @size += chunk.bytesize
    yield chunk
  end

  verify_content_length(@size)

  verify_to_path
end