Sha256: ec8cac3a6e7cdff7fd9b2fa3d53bebd67f1ddfce29c7683739e7492d91dfe9db

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require "forwardable"
require "resolv"

module HTTPX
  class Resolver::System
    include Resolver::ResolverMixin

    RESOLV_ERRORS = [Resolv::ResolvError,
                     Resolv::DNS::Requester::RequestError,
                     Resolv::DNS::EncodeError,
                     Resolv::DNS::DecodeError].freeze

    attr_reader :state

    def initialize(options)
      @options = Options.new(options)
      @resolver_options = @options.resolver_options
      @state = :idle
      resolv_options = @resolver_options.dup
      timeouts = resolv_options.delete(:timeouts)
      resolv_options.delete(:cache)
      @resolver = Resolv::DNS.new(resolv_options.empty? ? nil : resolv_options)
      @resolver.timeouts = timeouts || Resolver::RESOLVE_TIMEOUT
    end

    def closed?
      true
    end

    def empty?
      true
    end

    def <<(connection)
      hostname = connection.origin.host
      addresses = connection.addresses ||
                  ip_resolve(hostname) ||
                  system_resolve(hostname) ||
                  @resolver.getaddresses(hostname)
      throw(:resolve_error, resolve_error(hostname)) if addresses.empty?

      emit_addresses(connection, addresses)
    rescue Errno::EHOSTUNREACH, *RESOLV_ERRORS => e
      emit_resolve_error(connection, hostname, e)
    end

    def uncache(*); end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
httpx-0.18.6 lib/httpx/resolver/system.rb
httpx-0.18.5 lib/httpx/resolver/system.rb
httpx-0.18.4 lib/httpx/resolver/system.rb
httpx-0.18.3 lib/httpx/resolver/system.rb
httpx-0.18.2 lib/httpx/resolver/system.rb
httpx-0.18.1 lib/httpx/resolver/system.rb
httpx-0.18.0 lib/httpx/resolver/system.rb