Commit f3841743 by Jean-Philippe Doyle Committed by Mike Burns

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.
parent 7eb664f2
...@@ -28,9 +28,7 @@ module Paperclip ...@@ -28,9 +28,7 @@ module Paperclip
end end
def content_type_from_content def content_type_from_content
if @content.respond_to?(:content_type) @content.meta["content-type"].presence
@content.content_type
end
end end
def filename_from_content_disposition def filename_from_content_disposition
......
...@@ -3,10 +3,9 @@ require 'spec_helper' ...@@ -3,10 +3,9 @@ require 'spec_helper'
describe Paperclip::HttpUrlProxyAdapter do describe Paperclip::HttpUrlProxyAdapter do
before do before do
@open_return = StringIO.new("xxx") @open_return = StringIO.new("xxx")
@open_return.stubs(:content_type).returns("image/png") @open_return.stubs(:meta).returns("content-type" => "image/png")
@open_return.stubs(:meta).returns({}) Paperclip::HttpUrlProxyAdapter.any_instance.stubs(:download_content).
Paperclip::HttpUrlProxyAdapter.any_instance. returns(@open_return)
stubs(:download_content).returns(@open_return)
Paperclip::HttpUrlProxyAdapter.register Paperclip::HttpUrlProxyAdapter.register
end end
......
...@@ -16,6 +16,8 @@ describe Paperclip::UriAdapter do ...@@ -16,6 +16,8 @@ describe Paperclip::UriAdapter do
end end
context "a new instance" do context "a new instance" do
let(:meta) { { "content-type" => "image/png" } }
before do before do
Paperclip::UriAdapter.any_instance. Paperclip::UriAdapter.any_instance.
stubs(:download_content).returns(@open_return) stubs(:download_content).returns(@open_return)
...@@ -71,6 +73,7 @@ describe Paperclip::UriAdapter do ...@@ -71,6 +73,7 @@ describe Paperclip::UriAdapter do
context "a directory index url" do context "a directory index url" do
let(:content_type) { "text/html" } let(:content_type) { "text/html" }
let(:meta) { { "content-type" => "text/html" } }
before do before do
Paperclip::UriAdapter.any_instance. Paperclip::UriAdapter.any_instance.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment