Compare commits
2 commits
472eec8ae1
...
0d1e55d566
Author | SHA1 | Date | |
---|---|---|---|
|
0d1e55d566 | ||
|
6a5351ede0 |
1 changed files with 22 additions and 3 deletions
|
@ -261,9 +261,28 @@ class Request
|
||||||
begin
|
begin
|
||||||
addresses = [IPAddr.new(host)]
|
addresses = [IPAddr.new(host)]
|
||||||
rescue IPAddr::InvalidAddressError
|
rescue IPAddr::InvalidAddressError
|
||||||
Resolv::DNS.open do |dns|
|
begin
|
||||||
dns.timeouts = 5
|
Resolv::DNS.open do |dns|
|
||||||
addresses = dns.getaddresses(host)
|
dns.timeouts = 5
|
||||||
|
addresses = dns.getaddresses(host)
|
||||||
|
addresses = addresses.filter { |addr| addr.is_a?(Resolv::IPv6) }.take(2) + addresses.filter { |addr| !addr.is_a?(Resolv::IPv6) }.take(2)
|
||||||
|
end
|
||||||
|
rescue ResolvError
|
||||||
|
end
|
||||||
|
|
||||||
|
if addresses.empty?
|
||||||
|
# try /etc/hosts file
|
||||||
|
# https://github.com/mastodon/mastodon/issues/9436
|
||||||
|
Resolv::Hosts.new.each_address(host) do |address|
|
||||||
|
case address
|
||||||
|
when Resolv::IPv4::Regex
|
||||||
|
addresses << Resolv::IPv4.create(address)
|
||||||
|
when Resolv::IPv6::Regex
|
||||||
|
addresses << Resolv::IPv6.create(address)
|
||||||
|
else
|
||||||
|
raise ResolvError.new("cannot interpret as address: #{address}")
|
||||||
|
end
|
||||||
|
end
|
||||||
addresses = addresses.filter { |addr| addr.is_a?(Resolv::IPv6) }.take(2) + addresses.filter { |addr| !addr.is_a?(Resolv::IPv6) }.take(2)
|
addresses = addresses.filter { |addr| addr.is_a?(Resolv::IPv6) }.take(2) + addresses.filter { |addr| !addr.is_a?(Resolv::IPv6) }.take(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue