From 0d1e55d566b4d3c8b5daad086ba760c5f88fea52 Mon Sep 17 00:00:00 2001 From: Kouhai Date: Mon, 12 Feb 2024 02:35:47 -0800 Subject: [PATCH] th: smile sweet sadistic surprise service should've just hardcoded instead but noooooooooooo "needs to be decent" --- app/lib/request.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/lib/request.rb b/app/lib/request.rb index f8753fb191..0d3de9eb72 100644 --- a/app/lib/request.rb +++ b/app/lib/request.rb @@ -268,12 +268,22 @@ class Request 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.open do |dns| - 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) + 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) end end