Sha256: 0078855b1cdd2cca6df4bdfc732c1fdf2c25be7f2d775c54a68b4c428c605b69

Contents?: true

Size: 939 Bytes

Versions: 3

Compression:

Stored size: 939 Bytes

Contents

require 'set'
require 'vcr/util/hooks'

module VCR
  # @private
  class RequestIgnorer
    include VCR::Hooks

    define_hook :ignore_request

    LOCALHOST_ALIASES = %w( localhost 127.0.0.1 0.0.0.0 )

    def initialize
      ignore_request do |request|
        host = request.parsed_uri.host
        ignored_hosts.include?(host)
      end
    end

    def ignore_localhost=(value)
      if value
        ignore_hosts(*LOCALHOST_ALIASES)
      else
        ignored_hosts.reject! { |h| LOCALHOST_ALIASES.include?(h) }
      end
    end

    def localhost_ignored?
      (LOCALHOST_ALIASES & ignore_hosts.to_a).any?
    end

    def ignore_hosts(*hosts)
      ignored_hosts.merge(hosts)
    end

    def unignore_hosts(*hosts)
      ignored_hosts.subtract(hosts)
    end

    def ignore?(request)
      invoke_hook(:ignore_request, request).any?
    end

  private

    def ignored_hosts
      @ignored_hosts ||= Set.new
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
vcr-6.2.0 lib/vcr/request_ignorer.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/vcr-6.1.0/lib/vcr/request_ignorer.rb
vcr-6.1.0 lib/vcr/request_ignorer.rb