aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorfeld <feld@feld.me>2020-12-07 22:49:45 +0000
committerfeld <feld@feld.me>2020-12-07 22:49:45 +0000
commit9d0839504e5a3b11dcdf7686c3526c7cb3a6178c (patch)
tree5e52bf9b1f21362944e8240e4803b531e63e6914 /lib
parented76323776f2506cfefbe78c369fdb7ccfe3b650 (diff)
parent1403798820da21660fb8787ffaf9f54817597636 (diff)
downloadpleroma-9d0839504e5a3b11dcdf7686c3526c7cb3a6178c.tar.gz
Merge branch 'features/favicon-unreachable-instance' into 'develop'
instance: Do not fetch unreachable instances Closes #2346 See merge request pleroma/pleroma!3189
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/instances/instance.ex15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/pleroma/instances/instance.ex b/lib/pleroma/instances/instance.ex
index df471a39d..2e1696fe2 100644
--- a/lib/pleroma/instances/instance.ex
+++ b/lib/pleroma/instances/instance.ex
@@ -77,7 +77,7 @@ defmodule Pleroma.Instances.Instance do
)
end
- def reachable?(_), do: true
+ def reachable?(url_or_host) when is_binary(url_or_host), do: true
def set_reachable(url_or_host) when is_binary(url_or_host) do
with host <- host(url_or_host),
@@ -166,7 +166,8 @@ defmodule Pleroma.Instances.Instance do
defp scrape_favicon(%URI{} = instance_uri) do
try do
- with {:ok, %Tesla.Env{body: html}} <-
+ with {_, true} <- {:reachable, reachable?(instance_uri.host)},
+ {:ok, %Tesla.Env{body: html}} <-
Pleroma.HTTP.get(to_string(instance_uri), [{"accept", "text/html"}], pool: :media),
{_, [favicon_rel | _]} when is_binary(favicon_rel) <-
{:parse,
@@ -175,7 +176,15 @@ defmodule Pleroma.Instances.Instance do
{:merge, URI.merge(instance_uri, favicon_rel) |> to_string()} do
favicon
else
- _ -> nil
+ {:reachable, false} ->
+ Logger.debug(
+ "Instance.scrape_favicon(\"#{to_string(instance_uri)}\") ignored unreachable host"
+ )
+
+ nil
+
+ _ ->
+ nil
end
rescue
e ->