Fix HTTP not handling relative reidrects correctly
This commit is contained in:
parent
2a5bfb22db
commit
8d790b8af0
|
@ -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)
|
||||
|
||||
|
|
|
@ -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})
|
||||
|
|
Loading…
Reference in New Issue