diff --git a/lib/frenzy/http.ex b/lib/frenzy/http.ex index 1468b3d..c4a6975 100644 --- a/lib/frenzy/http.ex +++ b/lib/frenzy/http.ex @@ -2,7 +2,6 @@ defmodule Frenzy.HTTP do require Logger @redirect_codes [301, 302] - # @spec get(url :: String.t()) :: {:ok, HTTPoison.Response.t()} | {:error, String.()} def get(url) do case HTTPoison.get(url) do {:ok, %HTTPoison.Response{status_code: 200} = response} -> @@ -14,6 +13,16 @@ defmodule Frenzy.HTTP do |> Enum.find(fn {name, _value} -> name == "Location" end) |> case do {"Location", new_url} -> + new_url = + case URI.parse(new_url) do + %URI{host: nil, path: path} -> + # relative path + %URI{URI.parse(url) | path: path} |> URI.to_string() + + uri -> + uri + end + Logger.debug("Got 301 redirect from #{url} to #{new_url}") get(new_url) diff --git a/lib/frenzy/task/fetch_favicon.ex b/lib/frenzy/task/fetch_favicon.ex index 4f234d0..b61017e 100644 --- a/lib/frenzy/task/fetch_favicon.ex +++ b/lib/frenzy/task/fetch_favicon.ex @@ -19,6 +19,8 @@ defmodule Frenzy.Task.FetchFavicon do %URI{URI.parse(feed.feed_url) | path: nil, query: nil, fragment: nil} |> URI.to_string() end + Logger.debug("Fetching favicon for #{site_url}") + case fetch_favicon_from_webpage(site_url) do {:ok, favicon_data} -> changeset = Feed.changeset(feed, %{favicon: favicon_data})