module HTTPX::Resolver

  1. lib/httpx/resolver.rb
  2. lib/httpx/resolver/https.rb
  3. lib/httpx/resolver/native.rb
  4. lib/httpx/resolver/options.rb
  5. lib/httpx/resolver/resolver_mixin.rb
  6. lib/httpx/resolver/system.rb
  7. show all

Public Instance methods

cached_lookup (hostname)
[show source]
   # File lib/httpx/resolver.rb
26 def cached_lookup(hostname)
27   now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
28   @lookup_mutex.synchronize do
29     lookup(hostname, now)
30   end
31 end
cached_lookup_set (hostname, entries)
[show source]
   # File lib/httpx/resolver.rb
33 def cached_lookup_set(hostname, entries)
34   now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
35   entries.each do |entry|
36     entry["TTL"] += now
37   end
38   @lookup_mutex.synchronize do
39     @lookups[hostname] += entries
40     entries.each do |entry|
41       @lookups[entry["name"]] << entry if entry["name"] != hostname
42     end
43   end
44 end
decode_dns_answer (payload)
[show source]
    # File lib/httpx/resolver.rb
 81 def decode_dns_answer(payload)
 82   message = Resolv::DNS::Message.decode(payload)
 83   addresses = []
 84   message.each_answer do |question, _, value|
 85     case value
 86     when Resolv::DNS::Resource::IN::CNAME
 87       addresses << {
 88         "name" => question.to_s,
 89         "TTL" => value.ttl,
 90         "alias" => value.name.to_s,
 91       }
 92     when Resolv::DNS::Resource::IN::A,
 93          Resolv::DNS::Resource::IN::AAAA
 94       addresses << {
 95         "name" => question.to_s,
 96         "TTL" => value.ttl,
 97         "data" => value.address.to_s,
 98       }
 99     end
100   end
101   addresses
102 end
encode_dns_query (hostname, type: Resolv::DNS::Resource::IN::A)
[show source]
   # File lib/httpx/resolver.rb
73 def encode_dns_query(hostname, type: Resolv::DNS::Resource::IN::A)
74   Resolv::DNS::Message.new.tap do |query|
75     query.id = generate_id
76     query.rd = 1
77     query.add_question(hostname, type)
78   end.encode
79 end
generate_id ()
[show source]
   # File lib/httpx/resolver.rb
69 def generate_id
70   @identifier_mutex.synchronize { @identifier = (@identifier + 1) & 0xFFFF }
71 end
lookup (hostname, ttl)

do not use directly!

[show source]
   # File lib/httpx/resolver.rb
53 def lookup(hostname, ttl)
54   return unless @lookups.key?(hostname)
55 
56   @lookups[hostname] = @lookups[hostname].select do |address|
57     address["TTL"] > ttl
58   end
59   ips = @lookups[hostname].flat_map do |address|
60     if address.key?("alias")
61       lookup(address["alias"], ttl)
62     else
63       address["data"]
64     end
65   end
66   ips unless ips.empty?
67 end
uncache (hostname)
[show source]
   # File lib/httpx/resolver.rb
46 def uncache(hostname)
47   @lookup_mutex.synchronize do
48     @lookups.delete(hostname)
49   end
50 end