Hi all!
Recently I’ve been rewriting an old python downloader utility script in Elixir, but currently I am stuck in response header filtering.
I am starting my HTTPoison in a GenServer worker with:
options = [
stream_to: self(),
timeout: :infinity,
hackney: [:insecure, recv_timeout: :infinity]
]
worker = HTTPoison.get(url, %{}, options)
then, I threat the response messages with a simple approach:
case message do
%HTTPoison.AsyncHeaders{headers: headers} ->
# Code I need goes here
%HTTPoison.AsyncChunk{chunk: chunk} ->
IO.binwrite(file, chunk)
{:noreply, state}
%HTTPoison.AsyncEnd{} ->
File.close(file)
{:stop, :normal, state}
%HTTPoison.Error{reason: reason} ->
{:stop, reason, state}
_ ->
{:noreply, state}
end
My problem is that I need to strip from the headers the Content-Length and the status to handle errors like 404 or when my files exceed the specified maximum size. How could I accomplish that with HTTPoison? Am I doing something wrong?
Any help will be very appreciated!
Cheers.