From 8e18a415eb01f8bd295bf93679c685768b730a4e Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 24 Oct 2020 13:37:06 -0400 Subject: [PATCH] Fix error when attempting to convert image w/o Content-Type header to data URI --- lib/frenzy/pipeline/scrape_stage.ex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/frenzy/pipeline/scrape_stage.ex b/lib/frenzy/pipeline/scrape_stage.ex index 962356f..31575d2 100644 --- a/lib/frenzy/pipeline/scrape_stage.ex +++ b/lib/frenzy/pipeline/scrape_stage.ex @@ -144,13 +144,13 @@ defmodule Frenzy.Pipeline.ScrapeStage do case Network.http_get(absolute_url) do {:ok, %Mojito.Response{body: body, headers: headers}} -> - {"Content-Type", content_type} = - Enum.find(headers, fn {header, _value} -> header == "Content-Type" end) + Enum.find(headers, fn {header, _value} -> header == "Content-Type" end) + |> case do + {"Content-Type", content_type} when content_type in @content_type_allowlist -> + "data:#{content_type};base64,#{Base.encode64(body)}" - if content_type in @content_type_allowlist do - "data:#{content_type};base64,#{Base.encode64(body)}" - else - src + _ -> + src end _ ->