class Capybara::Server::Middleware

def call(env)

def call(env)
  if env['PATH_INFO'] == '/__identify__'
    [200, {}, [@app.object_id.to_s]]
  else
    request_uri = env['REQUEST_URI']
    @counter.increment(request_uri)
    begin
      @extended_app.call(env)
    rescue *@server_errors => e
      @error ||= e
      raise e
    ensure
      @counter.decrement(request_uri)
    end
  end
end

def clear_error

def clear_error
  @error = nil
end

def initialize(app, server_errors, extra_middleware = [])

def initialize(app, server_errors, extra_middleware = [])
  @app = app
  @extended_app = extra_middleware.inject(@app) do |ex_app, klass|
    klass.new(ex_app)
  end
  @counter = Counter.new
  @server_errors = server_errors
end

def pending_requests

def pending_requests
  @counter.value
end

def pending_requests?

def pending_requests?
  @counter.positive?
end