class Rack::Lint::Wrapper

def each

#
# ==== Enumerable Body
#
def each
  ## The Enumerable Body must respond to +each+.
  raise LintError, "Enumerable Body must respond to each" unless @body.respond_to?(:each)
  ## It must only be called once.
  raise LintError, "Response body must only be invoked once (#{@invoked})" unless @invoked.nil?
  ## It must not be called after being closed,
  raise LintError, "Response body is already closed" if @closed
  @invoked = :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