Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallback to ipv4/ipv6 in the event of an unreachable host error #101

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/tailwind.ex
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ defmodule Tailwind do
end
end

defp fetch_body!(url) do
defp fetch_body!(url, retry \\ true) do
scheme = URI.parse(url).scheme
url = String.to_charlist(url)
Logger.debug("Downloading tailwind from #{url}")
Expand Down Expand Up @@ -301,10 +301,16 @@ defmodule Tailwind do

options = [body_format: :binary]

case :httpc.request(:get, {url, []}, http_options, options) do
{:ok, {{_, 200, _}, _headers, body}} ->
case {retry, :httpc.request(:get, {url, []}, http_options, options)} do
{_, {:ok, {{_, 200, _}, _headers, body}}} ->
body

{true, {:error, {:failed_connect, [{:to_address, _}, {inet, _, reason}]}}}
when inet in [:inet, :inet6] and
reason in [:ehostunreach, :enetunreach, :eprotonosupport, :nxdomain] ->
:httpc.set_options(ipfamily: fallback(inet))
fetch_body!(url, false)

other ->
raise """
Couldn't fetch #{url}: #{inspect(other)}
Expand All @@ -324,6 +330,9 @@ defmodule Tailwind do
end
end

defp fallback(:inet), do: :inet6
defp fallback(:inet6), do: :inet

defp proxy_for_scheme("http") do
System.get_env("HTTP_PROXY") || System.get_env("http_proxy")
end
Expand Down
Loading