Skip to content
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
16 changes: 15 additions & 1 deletion lib/bumblebee/utils/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,21 @@ defmodule Bumblebee.Utils.HTTP do
try do
request = {url, headers}
http_opts = [ssl: http_ssl_opts()]
opts = [stream: :self, sync: false]

caller = self()

receiver = fn reply_info ->
request_id = elem(reply_info, 0)

# Cancel the request if the caller terminates
if Process.alive?(caller) do
send(caller, {:http, reply_info})
else
:httpc.cancel_request(request_id)
end
end

opts = [stream: :self, sync: false, receiver: receiver]

{:ok, request_id} = :httpc.request(:get, request, http_opts, opts)
download_loop(%{request_id: request_id, file: file, total_size: nil, size: nil})
Expand Down