Skip to content

Commit

Permalink
Fix ex aws requests (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
Karolk99 authored Apr 15, 2024
1 parent cd8bb9b commit 7045ea4
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lib/jellyfish/component/hls/httpoison.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@ defmodule Jellyfish.Component.HLS.HTTPoison do
@impl true
def request(method, url, body \\ "", headers \\ [], http_opts \\ []) do
case HTTPoison.request(method, url, body, headers, http_opts) do
{:ok, %HTTPoison.Response{status_code: status, headers: headers, body: body}} ->
{:ok, %{status_code: status, headers: headers, body: body}}

{:ok, %HTTPoison.Response{status_code: status, headers: headers}} ->
{:ok, %{status_code: status, headers: headers}}
{:ok, %HTTPoison.Response{} = response} ->
{:ok, adapt_response(response)}

{:error, %HTTPoison.Error{reason: reason}} ->
{:error, reason}
{:error, %{reason: reason}}
end
end

defp adapt_response(response) do
# adapt the response to fit the shape expected by ExAWS
flat_headers =
Enum.flat_map(response.headers, fn
{name, vals} when is_list(vals) -> Enum.map(vals, &{name, &1})
{name, val} -> [{name, val}]
end)

%{
body: response.body,
status_code: response.status_code,
headers: flat_headers
}
end
end

0 comments on commit 7045ea4

Please sign in to comment.