diff options
| author | href <href@random.sh> | 2017-12-12 11:45:55 +0100 | 
|---|---|---|
| committer | href <href@random.sh> | 2017-12-12 11:45:55 +0100 | 
| commit | 8e82547179e3e2dab3fde111f162d07e3fb98df7 (patch) | |
| tree | 0628cad94b9d97c9de91f557c6cf2fb40a407989 /lib | |
| parent | 9093b2cf4923274572729f46b688ab12f5a0bfdc (diff) | |
| download | pleroma-8e82547179e3e2dab3fde111f162d07e3fb98df7.tar.gz pleroma-8e82547179e3e2dab3fde111f162d07e3fb98df7.zip | |
fix content-type and fallback to image/jpeg
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pleroma/web/media_proxy/controller.ex | 12 | 
1 files changed, 9 insertions, 3 deletions
| diff --git a/lib/pleroma/web/media_proxy/controller.ex b/lib/pleroma/web/media_proxy/controller.ex index d6a1866bf..0ac70c9d8 100644 --- a/lib/pleroma/web/media_proxy/controller.ex +++ b/lib/pleroma/web/media_proxy/controller.ex @@ -33,10 +33,11 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do      options = [:insecure, {:follow_redirect, true}]      with \        {:ok, 200, headers, client} <- :hackney.request(:get, link, headers, "", options), -      {:ok, body} <- proxy_request_body(client) +      headers = Enum.into(headers, Map.new), +      {:ok, body} <- proxy_request_body(client), +      content_type <- proxy_request_content_type(headers, body)      do -      headers = Enum.into(headers, Map.new) -      {:ok, headers["Content-Type"], body} +      {:ok, content_type, body}      else        {:ok, status, _, _} ->          Logger.warn "MediaProxy: request failed, status #{status}, link: #{link}" @@ -73,5 +74,10 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do      {:error, :body_too_large}    end +  # TODO: the body is passed here as well because some hosts do not provide a content-type. +  # At some point we may want to use magic numbers to discover the content-type and reply a proper one. +  defp proxy_request_content_type(headers, _body) do +    headers["Content-Type"] || headers["content-type"] || "image/jpeg" +  end  end | 
