Module: HTTPX::Resolver
- Extended by:
- Resolver
- Included in:
- Resolver
- Defined in:
- lib/httpx/resolver.rb,
lib/httpx/resolver/cache.rb,
lib/httpx/resolver/entry.rb,
sig/resolver.rbs,
sig/resolver/cache.rbs,
sig/resolver/https.rbs,
sig/resolver/multi.rbs,
sig/resolver/native.rbs,
sig/resolver/system.rbs,
sig/resolver/resolver.rbs,
sig/resolver/cache/base.rbs
Defined Under Namespace
Modules: Cache, _Cache
Classes: Entry, HTTPS, Multi, Native, Resolver, System
Constant Summary
collapse
- RESOLVE_TIMEOUT =
[2, 3].freeze
Instance Method Summary
collapse
Instance Method Details
#decode_dns_answer(payload) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/httpx/resolver.rb', line 46
def decode_dns_answer(payload)
begin
message = Resolv::DNS::Message.decode(payload)
rescue Resolv::DNS::DecodeError => e
return :decode_error, e
end
return :no_domain_found if message.rcode == Resolv::DNS::RCode::NXDomain
return :message_truncated if message.tc == 1
if message.rcode != Resolv::DNS::RCode::NoError
case message.rcode
when Resolv::DNS::RCode::ServFail
return :retriable_error, message.rcode
else
return :dns_error, message.rcode
end
end
addresses = []
now = Utils.now
message.each_answer do |question, _, value|
case value
when Resolv::DNS::Resource::IN::CNAME
addresses << {
"name" => question.to_s,
"TTL" => (now + value.ttl),
"alias" => value.name.to_s,
}
when Resolv::DNS::Resource::IN::A,
Resolv::DNS::Resource::IN::AAAA
addresses << {
"name" => question.to_s,
"TTL" => (now + value.ttl),
"data" => value.address.to_s,
}
end
end
[:ok, addresses]
end
|
#encode_dns_query(hostname, type: Resolv::DNS::Resource::IN::A, message_id: generate_id) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/httpx/resolver.rb', line 39
def encode_dns_query(hostname, type: Resolv::DNS::Resource::IN::A, message_id: generate_id)
Resolv::DNS::Message.new(message_id).tap do |query|
query.rd = 1
query.add_question(hostname, type)
end.encode
end
|
#find_supported_ip_families ⇒ Array[Integer]
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/httpx/resolver.rb', line 97
def find_supported_ip_families
list = Socket.ip_address_list
begin
if list.any? { |a| a.ipv6? && !a.ipv6_loopback? && !a.ipv6_linklocal? }
[Socket::AF_INET6, Socket::AF_INET]
else
[Socket::AF_INET]
end
rescue NotImplementedError
[Socket::AF_INET]
end.freeze
end
|
#generate_id ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/httpx/resolver.rb', line 30
def generate_id
if Utils.in_ractor?
identifier = Ractor.store_if_absent(:httpx_resolver_identifier) { -1 }
Ractor.current[:httpx_resolver_identifier] = (identifier + 1) & 0xFFFF
else
id_synchronize { @identifier = (@identifier + 1) & 0xFFFF }
end
end
|
#self?.decode_dns_answer ⇒ dns_decoding_response
28
|
# File 'sig/resolver.rbs', line 28
def self?.decode_dns_answer: (String) -> dns_decoding_response
|
#self?.encode_dns_query ⇒ String
26
|
# File 'sig/resolver.rbs', line 26
def self?.encode_dns_query: (String hostname, ?type: dns_resource, ?message_id: Integer) -> String
|
#self?.generate_id ⇒ Integer
24
|
# File 'sig/resolver.rbs', line 24
def self?.generate_id: () -> Integer
|
#self?.id_synchronize { ... } ⇒ void
This method returns an undefined value.
32
|
# File 'sig/resolver.rbs', line 32
def self?.id_synchronize: () { () -> void } -> void
|
#self?.supported_ip_families ⇒ Array[ip_family]
22
|
# File 'sig/resolver.rbs', line 22
def self?.supported_ip_families: () -> Array[ip_family]
|
#supported_ip_families ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/httpx/resolver.rb', line 22
def supported_ip_families
if Utils.in_ractor?
Ractor.store_if_absent(:httpx_supported_ip_families) { find_supported_ip_families }
else
@supported_ip_families ||= find_supported_ip_families
end
end
|