Current section

Files

Jump to
sentry lib http.ex
Raw

lib/http.ex

defmodule HTTPResponse do
def run(url) do
{:ok, ref} = :hackney.get("https://wyms.streamguys1.com/live", [], '', [{:async, :once}])
receive do
{:hackney_response, ref, {:status, 200, reason}} ->
async_loop(ref)
{:hackney_response, ref, {:status, status, reason}} ->
{:error, status}
{:hackney_response, ref, {:error, {:closed, :timeout}}} ->
{:error, 408}
end
end
def async_loop(ref) do
:ok = :hackney.stream_next(ref)
receive do
{:hackney_response, ^ref, {:headers, headers}} ->
IO.inspect("HEADERS - #{inspect(headers)}")
async_loop(ref)
{:hackney_response, ^ref, :done} ->
IO.inspect("done")
{:hackney_response, ^ref, data} ->
IO.inspect("DATA - #{inspect(data)}")
async_loop(ref)
end
end
end