Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Rely on URI content_type only when provided.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
j15e authored and mike-burns committed May 25, 2018
1 parent 7eb664f commit f384174
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 1 addition & 3 deletions lib/paperclip/io_adapters/uri_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions spec/paperclip/io_adapters/uri_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit f384174

Please sign in to comment.