lib/httpx/io/resolver.rb in httpx-0.0.2 vs lib/httpx/io/resolver.rb in httpx-0.0.3

- old
+ new

@@ -26,11 +26,11 @@ def_delegator :@io, :closed? def initialize(options) @options = Options.new(options) # early return for edge case when there are no nameservers configured # but we still want to be able to static lookups using #resolve_hostname - @nameservers = self.class.nameservers or return + (@nameservers = self.class.nameservers) || return server = IPAddr.new(@nameservers.sample) @io = UDP.new(server, DNS_PORT) @read_buffer = "".b @addresses = {} @hostnames = [] @@ -53,11 +53,11 @@ @hostnames << hostname @callbacks << action query = build_query(hostname).encode log { "resolving #{hostname}: #{query.inspect}" } siz = @io.write(query) - log { "WRITE: #{siz} bytes..."} + log { "WRITE: #{siz} bytes..." } end def call return if @state == :closed return if @hostnames.empty? @@ -67,19 +67,19 @@ def dread(wsize = MAX_PACKET_SIZE) loop do siz = @io.read(wsize, @read_buffer) throw(:close, self) unless siz return if siz.zero? - log { "READ: #{siz} bytes..."} + log { "READ: #{siz} bytes..." } addrs = parse(@read_buffer) @read_buffer.clear next if addrs.empty? hostname = @hostnames.shift callback = @callbacks.shift addr = addrs.index(addrs.rand(addrs.size)) - log { "resolved #{hostname}: #{addr.to_s}"} + log { "resolved #{hostname}: #{addr}" } @addresses[hostname] = addr callback.call(addr) end end @@ -89,21 +89,21 @@ response = Resolv::DNS::Message.decode(frame) addrs = [] # The answer might include IN::CNAME entries so filters them out # to include IN::A & IN::AAAA entries only. - response.each_answer { |name, ttl, value| addrs << value.address if value.respond_to?(:address) } + response.each_answer { |_name, _ttl, value| addrs << value.address if value.respond_to?(:address) } - return addrs + addrs end def resolve_hostname(hostname) # Resolv::Hosts#getaddresses pushes onto a stack # so since we want the first occurance, simply # pop off the stack. resolv.getaddresses(hostname).pop - rescue + rescue StandardError end def resolv @resolv ||= Resolv::Hosts.new end @@ -127,9 +127,9 @@ private def get_address(host) Resolv::Hosts.new(host).getaddress - rescue + rescue StandardError end end end