From f384174392ce192c9d76bd447902fe8a3ecf70ad Mon Sep 17 00:00:00 2001 From: Jean-Philippe Doyle Date: Mon, 18 Jul 2016 15:33:00 -0400 Subject: [PATCH] Rely on URI content_type only when provided. As described in #2118, `OpenURI::Meta#content_type` will return `application/octet-stream` when no `content-type` header is set. Using the original `meta` fixes this issue. --- lib/paperclip/io_adapters/uri_adapter.rb | 4 +--- spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb | 7 +++---- spec/paperclip/io_adapters/uri_adapter_spec.rb | 3 +++ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/paperclip/io_adapters/uri_adapter.rb b/lib/paperclip/io_adapters/uri_adapter.rb index f4ed67908..26ea7edad 100644 --- a/lib/paperclip/io_adapters/uri_adapter.rb +++ b/lib/paperclip/io_adapters/uri_adapter.rb @@ -28,9 +28,7 @@ def cache_current_values end def content_type_from_content - if @content.respond_to?(:content_type) - @content.content_type - end + @content.meta["content-type"].presence end def filename_from_content_disposition diff --git a/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb b/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb index b5f48d485..6d674db5e 100644 --- a/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +++ b/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb @@ -3,10 +3,9 @@ describe Paperclip::HttpUrlProxyAdapter do before do @open_return = StringIO.new("xxx") - @open_return.stubs(:content_type).returns("image/png") - @open_return.stubs(:meta).returns({}) - Paperclip::HttpUrlProxyAdapter.any_instance. - stubs(:download_content).returns(@open_return) + @open_return.stubs(:meta).returns("content-type" => "image/png") + Paperclip::HttpUrlProxyAdapter.any_instance.stubs(:download_content). + returns(@open_return) Paperclip::HttpUrlProxyAdapter.register end diff --git a/spec/paperclip/io_adapters/uri_adapter_spec.rb b/spec/paperclip/io_adapters/uri_adapter_spec.rb index 681c6c014..827da5959 100644 --- a/spec/paperclip/io_adapters/uri_adapter_spec.rb +++ b/spec/paperclip/io_adapters/uri_adapter_spec.rb @@ -16,6 +16,8 @@ end context "a new instance" do + let(:meta) { { "content-type" => "image/png" } } + before do Paperclip::UriAdapter.any_instance. stubs(:download_content).returns(@open_return) @@ -71,6 +73,7 @@ context "a directory index url" do let(:content_type) { "text/html" } + let(:meta) { { "content-type" => "text/html" } } before do Paperclip::UriAdapter.any_instance.