Sha256: d558f67331a337b9d59d52e4e384f1725a4d41513951734aa90f04f5434809d0

Contents?: true

Size: 1.16 KB

Versions: 9

Compression:

Stored size: 1.16 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

    def initialize(options)
      @options = Options.new(options)
      roptions = @options.resolver_options
      @state = :idle
      @resolver = Resolv::DNS.new(roptions.nil? ? nil : roptions)
      @resolver.timeouts = roptions[:timeouts] if roptions
    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)
      return emit_resolve_error(connection, 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

9 entries across 9 versions & 1 rubygems

Version Path
httpx-0.6.4 lib/httpx/resolver/system.rb
httpx-0.6.3 lib/httpx/resolver/system.rb
httpx-0.6.2 lib/httpx/resolver/system.rb
httpx-0.6.1 lib/httpx/resolver/system.rb
httpx-0.6.0 lib/httpx/resolver/system.rb
httpx-0.5.1 lib/httpx/resolver/system.rb
httpx-0.5.0 lib/httpx/resolver/system.rb
httpx-0.4.1 lib/httpx/resolver/system.rb
httpx-0.4.0 lib/httpx/resolver/system.rb